Filter löschen
Filter löschen

How to call a symbolic function from cell array

7 Ansichten (letzte 30 Tage)
Annette Ventroni
Annette Ventroni am 27 Mai 2021
Beantwortet: Harimurali am 13 Okt. 2023
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 !

Antworten (1)

Harimurali
Harimurali am 13 Okt. 2023
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.

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by