Hello everyone. I would like to ask you two questions. The first problem: know A = [0.4,0.9], B = [2,9], and find the linear equation through A and B. The second problem: how to remove all zeros in a matrix. D=[1 2 3; 1 7 2; 6 2 7,0 0 0,0 0 0].

1 Ansicht (letzte 30 Tage)
I would like to ask you two questions. The first problem: know A = [0.4,0.9], B = [2,9], and find the linear equation through A and B. The second problem: how to remove all zeros in a matrix. D=[1 2 3; 1 7 2; 6 2 7,0 0 0,0 0 0].
  1 Kommentar
Wesley
Wesley am 1 Jun. 2021
The first problem has been solved.
coefficients = polyfit([x1, x2], [y1, y2], 1);
a = coefficients (1);
b = coefficients (2);

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 1 Jun. 2021
Question (1) is a simple LA exercise, but [A] needs to be 2-by-2. And then you can compute the roots of the system using linsolve(), ldivide(), \, etc operators.
Question (2): again the size of D is incorrectly defined. number of elements in each row has to be equal. Or D has to be row or column matrix containing some "0" elements. Once you fix this issue, you can solve the problem using logical indexing, e.g.: D(D==0) = [ ].
  2 Kommentare
Wesley
Wesley am 1 Jun. 2021
Thank you very much for your kind answer. I upload files such as D.mat, using your method can not remove 0.I don't know where my mistake is.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by