本文介绍了如何在Matlab中提取矩阵元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我有一个矩阵:A = [1, 5, 10]
,是否在一行上设置a1 = A(1), b1 = B(1)
等?我想做类似的事情:
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)
推荐答案
除了您可以在我链接的所有问题中找到的答案以外,还有另一种受此@gnovice帖子:
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
基本上等同于:[x y z] = num2cell(A){:}
(但是那是无效的语法)
Basically its equivalent to: [x y z] = num2cell(A){:}
(but thats non-valid syntax)
这篇关于如何在Matlab中提取矩阵元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!