Borrar filtros
Borrar filtros

How to call a symbolic function from cell array

7 visualizaciones (últimos 30 días)
Annette Ventroni
Annette Ventroni el 27 de Mayo de 2021
Respondida: Harimurali el 13 de Oct. de 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 !

Respuestas (1)

Harimurali
Harimurali el 13 de Oct. de 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.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by