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 vue (au cours des 30 derniers jours)
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

Réponses (2)

Chunru
Chunru le 23 Oct 2021
a=[1 2 3];
b=[4 5 6]
b = 1×3
4 5 6
n=length(a);
for i=1:n
s{i}=@(x) a(i)*x-b(i)*x;
end
s{1}(3)
ans = -9

Alan Stevens
Alan Stevens le 23 Oct 2021
Modifié(e) : Alan Stevens le 23 Oct 2021
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

Catégories

En savoir plus sur Electrical Block Libraries dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by