如何在Matlab中迭代列向量? [英] How to iterate over a column vector in Matlab?

查看:274
本文介绍了如何在Matlab中迭代列向量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

如何在MATLAB中迭代n维矩阵中的每个元素?

我有一个列向量 list 我想迭代它这个:

I have a column vector list which I would like to iterate like this:

for elm in list
   //do something with elm

如何?

推荐答案

在Matlab中,你可以直接迭代列表中的元素。如果您不需要知道当前正在使用哪个元素,这可能很有用。

In Matlab, you can iterate over the elements in the list directly. This can be useful if you don't need to know which element you're currently working on.

因此您可以写

for elm = list
%# do something with the element
end

请注意,Matlab会遍历的列,所以如果 list 是一个nx1向量,你可能想要转置它。

Note that Matlab iterates through the columns of list, so if list is a nx1 vector, you may want to transpose it.

这篇关于如何在Matlab中迭代列向量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆