how to count the number of terms in syms
12 次查看(过去 30 天)
显示 更早的评论
Hello!
I have a syms variable let's say A which is an addition of many terms say: A=a+b-c*a+a*b-d+... I want to count the number of added terms in A, how can I do that? my matlab version is 2012 by the way.
Thank you!
0 个评论
回答(3 个)
Ameer Hamza
2020-10-20
Try this
syms a b c d
A=a+b-c*a+a*b-d+a*c;
num_terms = numel(regexp(char(A), '[+-]?'))+1;
Walter Roberson
2020-10-20
feval(symengine, 'nops', A)
In newer releases you can numel(children(A)) but that is several years after your version
KSSV
2020-10-20
You can get the number of sym variables present in the work spce using:
s = whos ;
iwant = nnz(strcmp({s(:).class},'sym'))
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!