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

查看:11
本文介绍了如何在 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 的列,因此如果 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天全站免登陆