Filter löschen
Filter löschen

Loop through anonymous function

6 Ansichten (letzte 30 Tage)
Cam B
Cam B am 6 Mär. 2022
Beantwortet: Steven Lord am 6 Mär. 2022
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

Antworten (1)

Steven Lord
Steven Lord am 6 Mär. 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)
ans = 1×5
1 4 9 16 25

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by