2010-09-18 124 views
1

可能重複:
MATLAB Easiest way to assign elements of a vector to individual variables.
How do I do multiple assignment in MATLAB?如何提取matlab中的矩陣元素?

如果我有一個矩陣:A = [1, 5, 10],做我設置a1 = A(1), b1 = B(1)等在同一行?我想要做的事,如:

[a1 a2 a3] = Blah(A) 
+2

此問題已被多次詢問:http://stackoverflow.com/questions/2337126/how-do-i-do-multiple-assignment-in -matlab,http://stackoverflow.com/questions/2893356/matlab-easiest-way-to-assign-ele ments-of-a-vector-to-individual-variables,http://stackoverflow.com/questions/2740704/is-there-anything-like-deal-for-normal-matlab-array – Amro 2010-09-18 21:48:52

回答

2
從答案

除了可以在我聯繫到的所有問題發現,這裏的尚未使用的subsref另一個班輪本@gnovice post啓發:

>> A = [1 5 10]; 
>> [x y z] = subsref(num2cell(A), struct('type','{}','subs',{{':'}})) 
x = 
    1 
y = 
    5 
z = 
    10 

基本上它相當於:[x y z] = num2cell(A){:}(但那是無效的語法)