indexing - How can I index a MATLAB array returned by a function without first assigning it to a local variable? -
for example, if want read middle value magic(5)
, can this:
m = magic(5); value = m(3,3);
to value == 13
. i'd able 1 of these:
value = magic(5)(3,3); value = (magic(5))(3,3);
to dispense intermediate variable. however, matlab complains unbalanced or unexpected parenthesis or bracket
on first parenthesis before 3
.
is possible read values array/matrix without first assigning variable?
it is possible want, if use functional form of indexing operator. when perform indexing operation using ()
, making call subsref function. so, though can't this:
value = magic(5)(3,3);
you can this:
value = subsref(magic(5),struct('type','()','subs',{{3,3}}));
ugly, possible, ;)
in general, have change indexing step function call don't have 2 sets of parentheses following 1 another. way define own anonymous function subscripted indexing:
subindex = @(a,r,c) a(r,c); %# anonymous function index matrix value = subindex(magic(5),3,3); %# use function index matrix
however, when said , done temporary local variable solution much more readable, , suggest.