how to count the number of terms in syms
조회 수: 2 (최근 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에서 Special Values에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!