开发者

How do I extract matrix elements in matlab? [duplicate]

This question already has answers here: Closed 12 开发者_Go百科years ago.

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜