When trying:
a = [ 1 1 ; 1 1 ];
size(a)(1)
I get
Error: ()-indexing must appear last in an index
expression
M
Because you can't index the result of a function like that in MATLAB without creating a temporary.
temp = size(a);
temp(1)
will work. There are often other ways of getting what you want, however. In your example, you can make use of the dim
argument in the function size(X,dim)
:
size(a,1)
That will get you the size of the first dimension directly, avoiding the need to create a temporary variable.