importing only one element of a matrix into a function

1 回表示 (過去 30 日間)
Sherwin
Sherwin 2022 年 4 月 26 日
回答済み: Voss 2022 年 4 月 26 日
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.

採用された回答

Voss
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 件)

カテゴリ

Help Center および File ExchangeCorrelation and Convolution についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by