I would like to create a handle function by for loop in matlab, but it does not work. I will be thankful if some body help me.
1 回表示 (過去 30 日間)
古いコメントを表示
a=[1 2 3];
b=[4 5 6]
n=length(a);
for i=1:n
s(i)=@(x) a(i)*x-b(i)*x;
end
0 件のコメント
回答 (2 件)
Chunru
2021 年 10 月 23 日
a=[1 2 3];
b=[4 5 6]
n=length(a);
for i=1:n
s{i}=@(x) a(i)*x-b(i)*x;
end
s{1}(3)
0 件のコメント
Alan Stevens
2021 年 10 月 23 日
編集済み: Alan Stevens
2021 年 10 月 23 日
More like this?
sfn = @(x,a,b) (a - b)*x;
a=[1 2 3];
b=[4 5 6];
n=length(a);
x = 1; % specify whatever x value you want
for i=1:n
s(i) = sfn(x,a(i),b(i));
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Numeric Types についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!