How to get the columns of non zero matrix?

1 回表示 (過去 30 日間)
fyza affandi
fyza affandi 2018 年 12 月 3 日
編集済み: YT 2018 年 12 月 3 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by