how to count the number of terms in syms
    2 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
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 comentarios
Respuestas (3)
  Ameer Hamza
      
      
 el 20 de Oct. de 2020
        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
      
      
 el 20 de Oct. de 2020
        feval(symengine, 'nops', A)
In newer releases you can numel(children(A)) but that is several years after your version
1 comentario
  KSSV
      
      
 el 20 de Oct. de 2020
        You can get the number of sym variables present in the work spce using: 
s = whos ;
iwant = nnz(strcmp({s(:).class},'sym'))
0 comentarios
Ver también
Categorías
				Más información sobre Special Values en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



