Calculate the length of symbolic expression

13 visualizaciones (últimos 30 días)
T S Singh
T S Singh el 18 de Feb. de 2020
Comentada: T S Singh el 19 de Feb. de 2020
Hi,
I am trying to caculate the total length of a symbolic expression.
Eg.
syms x a b
df=x^2+2*a*b
I want to cacluale the length of 'df', in my case the answer should be nine (including operator).
I am using MATLAB 2015a.
Any help please.

Respuesta aceptada

KSSV
KSSV el 18 de Feb. de 2020
S = char(df) ; % convert sym to string
idx = strfind(s,' ') ; % get empty spaces
S(idx) = [] ; % remove the mepty spaces
iwant = length(S)

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by