Find the the inices of columns of nonzero entries from rows of a matrix
1 回表示 (過去 30 日間)
古いコメントを表示
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]
0 件のコメント
採用された回答
madhan ravi
2019 年 2 月 13 日
O=arrayfun(@(x)find(k(x,:)),1:size(k,1),'un',0);
celldisp(O)
3 件のコメント
Guillaume
2019 年 2 月 13 日
Another option:
cellfun(@nonzeros, num2cell(k, 2), 'UniformOutput', false); %you case use @find instead of @nonzeros if you want
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!