How to call a symbolic function from cell array
4 ビュー (過去 30 日間)
古いコメントを表示
Hello, i have a problem with calling a symbolic function that is stored in cell array.
syms pp(x);
>> pp(x) = piecewise(x<0 , 0, 0<=x<=0.9 ,0.8, .9 <x<=2.7 ,0.9, 2.7<x<=4.5, 0.8, 4.5 <x<=8.1 , 0.4, 8.1 <x<=13.5 , 0.05);
>>
>> PP=cell(10,1);
>> PP{1}=pp(x);
>> pp(3)
ans =
4/5
>> PP{1}(3)
Index exceeds the number of array elements (1).
Error in sym/subsref (line 902)
R_tilde = builtin('subsref',L_tilde,Idx);
>>
Someone can help me understand how i have to call it? Thank you very much !
0 件のコメント
回答 (1 件)
Harimurali
2023 年 10 月 13 日
Hi Annette,
I understand that you want to know if there is a way to call the symbolic function stored in a cell array. In this case, calling this symbolic function from the cell array is not possible.
Alternatively, the same can be achieved by creating a MATLAB function handle for the ‘piecewise’ function and storing it in the cell array. This can be called directly by indexing the cell array. The sample MATLAB code for this is as follows:
pp = @(x, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~, ~)piecewise(x < 0, 0, 0 <= x <= 0.9, 0.8, 0.9 < x <= 2.7, 0.9, 2.7 < x <= 4.5, 0.8, 4.5 < x <= 8.1, 0.4, 8.1 < x <= 13.5, 0.05);
PP = cell(10, 1);
PP{1} = pp;
PP{1}(3);
Please refer to the following documentation for more information about function handles in MATLAB:
I hope this helps.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Symbolic Math Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!