Calculate the length of symbolic expression

조회 수: 7 (최근 30일)
T S Singh
T S Singh 2020년 2월 18일
댓글: T S Singh 2020년 2월 19일
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.

채택된 답변

KSSV
KSSV 2020년 2월 18일
S = char(df) ; % convert sym to string
idx = strfind(s,' ') ; % get empty spaces
S(idx) = [] ; % remove the mepty spaces
iwant = length(S)

추가 답변 (0개)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by