Skip to content

Commit

Permalink
Coarse fix for #595
Browse files Browse the repository at this point in the history
  • Loading branch information
ehennestad committed Sep 14, 2024
1 parent c51099f commit fc9ca2a
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion +types/+untyped/@DataStub/load_mat_style.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,14 @@
, iDimension, dimensionSize);
end

if isscalar(userSelection) && ~ischar(userSelection{1})
if isscalar(userSelection) && isempty(userSelection{1})
% If userselection (indices) is empty, get the first element of this
% DataStub and try to return an empty representation of that type.
data = obj.load_mat_style(1);
data = getEmptyRepresentation(data);
return

elseif isscalar(userSelection) && ~ischar(userSelection{1})
% linear index into the fast dimension.
orderedSelection = unique(userSelection{1});

Expand Down Expand Up @@ -187,4 +194,19 @@
indexKeyIndex(indexKeyIndexNextIndex) = indexKeyIndex(indexKeyIndexNextIndex) + 1;
indexKeyIndex((indexKeyIndexNextIndex+1):end) = 1;
end
end


function emptyInstance = getEmptyRepresentation(nonEmptyInstance)
try
emptyInstance = nonEmptyInstance;
emptyInstance(:) = [];
catch ME
switch ME.identifier
case 'MATLAB:table:LinearSubscript'
emptyInstance(:, :) = [];
otherwise
error('Not implemented for value of type: "%s"', class(nonEmptyInstance))
end
end
end

0 comments on commit fc9ca2a

Please sign in to comment.