How to get rid of zeros in a matrix?
    5 views (last 30 days)
  
       Show older comments
    
If you run the code you'll notice that aSol is a 4x1 but two of the numbers are zeros and the other two are the same, how can I remove the zeros and make asol equals to a 1x1 number since two of the numbers are the same. Also, is there any way to make a loop to get the values of sol saved separately so i do not have to write asol=sol.a    bsol=sol.b ....
k1 = 0.3;
k2 = 0.3;
k3 = 0.4;
k4 = 0.05;
k5 = 0.77;
k6 = 1.373;
k7 = 0.48;
k8 = 0.0017;
k9 = 0.094;
k10 = 3.76;
syms a b c d e f g h i j k m n l s t v w x
eqn1 = k1*w==a;
eqn2 = k2*k==b;
eqn3 = k3*m==c;
eqn4 = k4*n*w==d;
eqn5 = k5*l==e;
eqn6 = k6*s==f;
eqn7 = k7*t*s==g;
eqn8 = k8*v==h;
eqn9 = k9*v==i;
eqn10 = k10*x==j;
eqn11 = a-b==k;
eqn12 = b-c==m;
eqn13 = c-d==n;
eqn14 = d-e==l;
eqn15 = e-g-f==s;
eqn16 = f-g==t;
eqn17 = g-h-i==v;
eqn18 = -a-d+j==w;
eqn19 = a+d-j==x;
sol = solve([eqn1, eqn2, eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9,eqn10,eqn11,eqn12,eqn13,eqn14,eqn15,eqn16,eqn17,eqn18,eqn19], [a,b,c,d,e,f,g,h,i,j,k,m,n,l,s,t,v,w,x]);
aSol = sol.a
bSol = sol.b
cSol = sol.c
1 Comment
  Hiro Yoshino
    
 on 21 Oct 2022
				Can you make the question a bit simpler?
Please do not paste all your script but extract your scope you'd like to discuss.
Accepted Answer
  Walter Roberson
      
      
 on 21 Oct 2022
        k1 = 0.3;
k2 = 0.3;
k3 = 0.4;
k4 = 0.05;
k5 = 0.77;
k6 = 1.373;
k7 = 0.48;
k8 = 0.0017;
k9 = 0.094;
k10 = 3.76;
syms a b c d e f g h i j k m n l s t v w x
assume(a ~= 0)
eqn1 = k1*w==a;
eqn2 = k2*k==b;
eqn3 = k3*m==c;
eqn4 = k4*n*w==d;
eqn5 = k5*l==e;
eqn6 = k6*s==f;
eqn7 = k7*t*s==g;
eqn8 = k8*v==h;
eqn9 = k9*v==i;
eqn10 = k10*x==j;
eqn11 = a-b==k;
eqn12 = b-c==m;
eqn13 = c-d==n;
eqn14 = d-e==l;
eqn15 = e-g-f==s;
eqn16 = f-g==t;
eqn17 = g-h-i==v;
eqn18 = -a-d+j==w;
eqn19 = a+d-j==x;
sol = solve([eqn1, eqn2, eqn3,eqn4,eqn5,eqn6,eqn7,eqn8,eqn9,eqn10,eqn11,eqn12,eqn13,eqn14,eqn15,eqn16,eqn17,eqn18,eqn19], [a,b,c,d,e,f,g,h,i,j,k,m,n,l,s,t,v,w,x]);
solabc = unique(subs([a, b, c], sol), 'rows')
EXPAND = @(C) C{:};
[aSol, bSol, cSol] = EXPAND(num2cell(solabc))
0 Comments
More Answers (0)
See Also
Categories
				Find more on Design and Simulate SerDes Systems in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!