How to get rid of zeros in a matrix?

조회 수: 4 (최근 30일)
Pipe
Pipe 2022년 10월 21일
답변: Walter Roberson 2022년 10월 21일
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
Hiro Yoshino
Hiro Yoshino 2022년 10월 21일
Can you make the question a bit simpler?
Please do not paste all your script but extract your scope you'd like to discuss.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2022년 10월 21일
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')
solabc = 
EXPAND = @(C) C{:};
[aSol, bSol, cSol] = EXPAND(num2cell(solabc))
aSol = 
bSol = 
cSol = 

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Design and Simulate SerDes Systems에 대해 자세히 알아보기

태그

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by