フィルターのクリア

Loop through anonymous function

6 ビュー (過去 30 日間)
Cam B
Cam B 2022 年 3 月 6 日
回答済み: Steven Lord 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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by