Loop through anonymous function
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
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)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!