How to get the columns of non zero matrix?

1 vue (au cours des 30 derniers jours)
fyza affandi
fyza affandi le 3 Déc 2018
Modifié(e) : YT le 3 Déc 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 commentaire
Adam Danz
Adam Danz le 3 Déc 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];

Connectez-vous pour commenter.

Réponse acceptée

YT
YT le 3 Déc 2018
Modifié(e) : YT le 3 Déc 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

Plus de réponses (0)

Catégories

En savoir plus sur Matrices and Arrays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by