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.
2 次查看(过去 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 个)
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!