importing only one element of a matrix into a function
1 回表示 (過去 30 日間)
古いコメントを表示
Hi, I have a loop which calls a function in it. The function needs only one element of the matrix that the loop is counting. Can I use such a code?
O = [1 2; 3 4];
for i = 1:size(O,1)
f = M (O(i,1));
end
where M is a function? if yes, can i use O(i,1) in the function as the arguments??
if no, what do you suggest instead? If I import the entire O, I can't run the function M only on one element of O, I would have to have a loop in the function M and run M on all elements of O and this is not the output that I need.
0 件のコメント
採用された回答
Voss
2022 年 4 月 26 日
Yes, that's fine. (Try it and see.)
The only thing I would point out is that you probably don't want to overwrite f each time, but I assume that's an artifact of how the sample code is set up here and is not a problem in your real code.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!