Defining function handles in a for loop
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone,
I have trying to define a series of function handles that are very similar. They only differ by their constant coefficients. They general idea is that I want to define functions s1 to s5 such that
for i =1:5
S_i = @(x) z(i)/3.*(p(i+1) -x)^3
end
where each s takes on their coefficeints from vectors z and p, as shown. But it seems like Matlab does not allow an array of function handles. What should I do?
Thanks a lot guys!
1 Kommentar
Stephen23
am 7 Nov. 2020
"You can create an array of function handles by collecting them into a cell or structure array."
Antworten (1)
Walter Roberson
am 7 Nov. 2020
for i =1:5
S_i{i} = @(x) z(i)/3.*(p(i+1) -x)^3
end
6 Kommentare
Walter Roberson
am 8 Nov. 2020
S_i{i} = @(x) z(i)/3.*(p(i+1) -x).^3 %notice .^ instead of ^
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!