Loop through anonymous function

6 次查看(过去 30 天)
Cam B
Cam B 2022-3-6
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

回答(1 个)

Steven Lord
Steven Lord 2022-3-6
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)
ans = 1×5
1 4 9 16 25

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by