MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   资料存档 (https://www.labfans.com/bbs/forumdisplay.php?f=72)
-   -   Matlab中的for循环 (https://www.labfans.com/bbs/showthread.php?t=26741)

poster 2019-12-14 20:46

Matlab中的for循环
 
如何在循环中获取向量的每个索引,这是将向量的值传递给函数

vector =[ 20 , 30 , 60 ,45 ,26 ,17 ,28,9, 10,3 ] n = 10 for i=1:n somefunt( vector(i) ); end 所以这是翻译

somefunt( vector(20) ); somefunt( vector(30) ); somefunt( vector(60) ); ... 这该怎么做?



[B]回答:[/B]

如果要在vector [URL="http://www.mathworks.com/help/techdoc/ref/for.html"]循环[/URL]中将vector所有值传递给函数somefunt ,则可以将vector用作循环值,如下所示:

for i = vector somefunt(i); end 这等效于:

somefunt(20); somefunt(30); somefunt(60); ...

[url=https://stackoverflow.com/questions/5467264]更多&回答...[/url]


所有时间均为北京时间。现在的时间是 23:21

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.