Using vector input to anonymous function
古いコメントを表示
If a have a function such as:
fptest = @(osf, T) T^2 - log(osf);
fpout(fptest, 2, 3, 4) %evaluates T in the end
In the first line, is it possible to input "osf" as a vector? For example, osf = [1 2 3] so that fpout evaluates fptest for values of T at osf = 1, 2, and 3 in 3 separate runs?
Thanks, Abdulla
採用された回答
その他の回答 (1 件)
Abdul Basith Ashraf
2019 年 9 月 6 日
>>y = @(x) 2.2*x/(1+1.2*x);
>>x = linspace(0,1);
>>y(x)
ans =
0.7398
In the above, I tried passing a vector 'x' to a function handle 'y'. I was expecting 'ans' to be a vector mapping each 'x' to 'y(x)' but it returned a single value. Why is that? Also help me out to get my vector output.
Thanks
1 件のコメント
In the future, please start a new question of your own as you're definitivetly not answering the original question with your answer.
Your problem has nothing to do with function handles or anonymous functions. It's all to do with the fact that your doing a matrix division / which returns a scalar instead of an element-wise division ./ (which would return a vector).
カテゴリ
ヘルプ センター および File Exchange で Event Functions についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!