Find the the inices of columns of nonzero entries from rows of a matrix

1 回表示 (過去 30 日間)
Mazhar Ali
Mazhar Ali 2019 年 2 月 13 日
コメント済み: madhan ravi 2019 年 2 月 13 日
Hello! Every one
I have a matrix k= [0 0 1 1 0 0 0 0 0 0 0 0 0;...
0 0 0 1 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 0 0 0 0 0 0 0 0;...
0 0 0 0 0 01 0 0 0 0 0 0]
I want to get the indices of nonzero columns in each row
Output be like O1 = [3 4]
O2 = [4]
O3 = []
o4 = [7]

採用された回答

madhan ravi
madhan ravi 2019 年 2 月 13 日
O=arrayfun(@(x)find(k(x,:)),1:size(k,1),'un',0);
celldisp(O)
  3 件のコメント
Guillaume
Guillaume 2019 年 2 月 13 日
Another option:
cellfun(@nonzeros, num2cell(k, 2), 'UniformOutput', false); %you case use @find instead of @nonzeros if you want
madhan ravi
madhan ravi 2019 年 2 月 13 日
Thank you Guillaume!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by