フィルターのクリア

How to call a symbolic function from cell array

1 回表示 (過去 30 日間)
Annette Ventroni
Annette Ventroni 2021 年 5 月 27 日
回答済み: Harimurali 2023 年 10 月 13 日
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 !

回答 (1 件)

Harimurali
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.

カテゴリ

Help Center および File ExchangeSymbolic Math Toolbox についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by