Loop through anonymous function
5 views (last 30 days)
Show older comments
I am trying to loop through an anonymous function where one of the inputs, z, is between 20 and 60. How would I loop through this in order to find the value of 'newFunction' each time z is a new value from 20 to 60 (so essenitally needing 40 values)
newFunction = @(X1,z) vector\vector1
0 Comments
Answers (1)
Steven Lord
on 6 Mar 2022
As written the body of your anonymous function is completely independent of X1 and z.
I suspect that vector and/or vector1 are in some way supposed to be functions of X1 and/or z. If that's the case (if they're anonymous functions) you need to call them with the inputs explicitly.
f = @(x, n) x.^n;
g = @(x) f(x, 2); % Calling f using the data with which g was called
g(1:5)
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!