Calculate the length of symbolic expression

9 vues (au cours des 30 derniers jours)
T S Singh
T S Singh le 18 Fév 2020
Commenté : T S Singh le 19 Fév 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.

Réponse acceptée

KSSV
KSSV le 18 Fév 2020
S = char(df) ; % convert sym to string
idx = strfind(s,' ') ; % get empty spaces
S(idx) = [] ; % remove the mepty spaces
iwant = length(S)

Plus de réponses (0)

Catégories

En savoir plus sur Symbolic Math Toolbox dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by