From fc9ca2a10af02fc3d1d23b933b7a51b30e1d2351 Mon Sep 17 00:00:00 2001 From: ehennestad Date: Sat, 14 Sep 2024 14:36:03 +0200 Subject: [PATCH] Coarse fix for #595 --- +types/+untyped/@DataStub/load_mat_style.m | 24 +++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/+types/+untyped/@DataStub/load_mat_style.m b/+types/+untyped/@DataStub/load_mat_style.m index a6fa1f16..12d281ca 100644 --- a/+types/+untyped/@DataStub/load_mat_style.m +++ b/+types/+untyped/@DataStub/load_mat_style.m @@ -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}); @@ -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 \ No newline at end of file