poster
2019-12-14, 20:46
如何在循环中获取向量的每个索引,这是将向量的值传递给函数
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) ); ... 这该怎么做?
回答:
如果要在vector 循环 (http://www.mathworks.com/help/techdoc/ref/for.html)中将vector所有值传递给函数somefunt ,则可以将vector用作循环值,如下所示:
for i = vector somefunt(i); end 这等效于:
somefunt(20); somefunt(30); somefunt(60); ...
更多&回答... (https://stackoverflow.com/questions/5467264)
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) ); ... 这该怎么做?
回答:
如果要在vector 循环 (http://www.mathworks.com/help/techdoc/ref/for.html)中将vector所有值传递给函数somefunt ,则可以将vector用作循环值,如下所示:
for i = vector somefunt(i); end 这等效于:
somefunt(20); somefunt(30); somefunt(60); ...
更多&回答... (https://stackoverflow.com/questions/5467264)