How to get the columns of non zero matrix?

1 Ansicht (letzte 30 Tage)
fyza affandi
fyza affandi am 3 Dez. 2018
Bearbeitet: YT am 3 Dez. 2018
I have a matrix named A
a= [1 0 0 0 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0;
0 1 0 0 0 0 0 0 0 0;
0 0 1 0 0 0 0 0 0 0;
0 0 0 1 0 0 0 0 0 0;
0 0 0 0 1 0 0 0 0 0;
0 0 0 0 0 1 0 0 0 0;
0 0 0 0 0 0 1 1 0 0;
0 0 0 0 0 0 0 0 1 1];
How can I have the number of column of non-zero number in a matrix? (Check by rows)
The result would be
Column = [1 0 2 3 4 5 6 7 8 9 1 0]
  1 Kommentar
Adam Danz
Adam Danz am 3 Dez. 2018
I don't understand the quesiton. Is the output merely 1,2,3,4,5,6,7,8,9,10? Are you just cumulatively counting the number of 1s by row?
What would be the result of this input?
a = [ 1 0 1 1;
0 0 0 1;
0 0 0 0;
1 1 1 1];

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

YT
YT am 3 Dez. 2018
Bearbeitet: YT am 3 Dez. 2018
Your example is a bit vague, but if the main question is to find the non-zero values in the matrix, I would suggest using the following
[r c] = find(a~=0) %returns rows (r) and columns (c) of non-zero values

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays 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