This problem arose when I was answering this question . There must be some stupid mistake that I am making, but I canβt understand what kind of mistake ...
myMatrix = [22 33; 44 55]
Return:
>> subsref(myMatrix, struct('type','()','subs',{{[1 2]}} ) ); ans = 22 44
When using it with cells:
myCell = {2 3; 4 5}
Return:
>> subsref(myCell,struct('type','{}','subs',{{[1 2]}} ) ); ans = 2 % WHATTT?? Shouldn't this be 2 and 4 Matlab??
Checking the subsref documentation , we see:
See how MATLAB calls subsref for an expression:
A {1: 2} Syntax A {1: 2} calls B = subsref (A, S), where S.type = '{}' and S.subs = {[1 2]}.
This does not seem to be the case, because the return value of subsref is only the first argument, and not all arguments.
Then if you do this:
>> [a,b]=subsref(myCell,struct('type','{}','subs',{{[1 2]}} ) ) a = 2 b = 4 % Surprise!
But this is not the same as myCell {[2 4]}, which will automatically return:
>> myCell{[1 2]} ans = 2 ans = 4
Will I need to use subsref with one output for each index that I use to access myCell , or am I missing something?