forming a function handles in matrix
10 ビュー (過去 30 日間)
古いコメントを表示
I want to form a set of function handles in a row matrix.
i wrote script like below.
w = 2;
Nr = 20
nr = @(phi)zeros(1, Nr);
wr = @(phi)zeros(1, Nr);
for n = 1:Nr
for i = 1:w
Awr = 50*(cos(i*2)-cos(i*9));
nr(1, n) = @(phi)nr(1, n)+Awr*cos(i*1.7);
end
wr(1, n) = @(phi)nr(1, n)
end
Iam getting the below error
Nonscalar arrays of function handles are not allowed; use cell arrays instead.
how to rectify this??
0 件のコメント
回答 (1 件)
Steven Lord
2021 年 10 月 4 日
MATLAB used to allow nonscalar arrays of function handles, but that functionality was removed probably 10 to 15 years ago. As the error message suggested, store your function handles in a cell array instead.
7 件のコメント
Stephen23
2021 年 10 月 6 日
編集済み: Stephen23
2021 年 10 月 6 日
@Bathala Teja: function handles cannot be multiplied (or have any numeric operation applied to them). But you can certainly evaluate the function handles (just as Steven Lord showed) and multiply their outputs:
f{1}(3)*f{2}(3)
% ^^^ ^^^ Evaluate!
参考
カテゴリ
Help Center および File Exchange で Particle Swarm についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!