How do I extract matrix elements in matlab? [duplicate]
Possible Duplicates:
MATLAB Easiest way to assign elements of a vector to individual variables. How do I do multiple assignment in MATLAB?
If I have a matrix: A = [1, 5, 10]
, do I set a1 = A(1), b1 = B(1)
, etc. on one line? I want to do something like:
[a1 a2 a3] = Blah(A)
Aside from the answers you can find in all the questions I linked to, here's yet another one-liner inspired by this @gnovice post using SUBSREF:
>> A = [1 5 10];
>> [x y z] = subsref(num2cell(A), struct('type','{}','subs',{{':'}}))
x =
1
y =
5
z =
10
Basically its equivalent to: [x y z] = num2cell(A){:}
(but thats non-valid syntax)
精彩评论