如何提取matlab中的矩阵元素?
问题描述:
可能重复:
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)
答
从答案
除了可以在我联系到的所有问题发现,这里的尚未使用的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){:}
(但那是无效的语法)
此问题已被多次询问: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