How to get the columns of non zero matrix?

1 次查看(过去 30 天)
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 个评论
Adam Danz
Adam Danz 2018-12-3
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];

请先登录,再进行评论。

采纳的回答

YT
YT 2018-12-3
编辑:YT 2018-12-3
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by