Finding the indices of duplicate maximum number of non zero element in matrix

1 次查看(过去 30 天)
I have this matrix
A=[-1 -0.3313 0 1 0.55 -0.2186 -1.0041 -0.0297 0 0.0041 0 0.0297;
0 0 0 0 1.09 -0.09 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0.5 0.5;
0 0 0 0 0 0 0 0 0 0 -0.375 1.375;
-1 0.2108 0 1 -0.35 0.1392 -0.9675 0.238 0 -0.0325 0 -0.238];
I want to find a rows that gives me maximum number of non zero element.
answer should be row=[1,5]
I use this one [~,Q1]=max(sum(A~=0,2) ) but it does not give [1,5]

采纳的回答

madhan ravi
madhan ravi 2019-1-7
编辑:madhan ravi 2019-1-7
EDITED
Note: max only returns the index of the max value at the first instant so in order to find all the indices of max value you would have to use find().
A=[-1 -0.3313 0 1 0.55 -0.2186 -1.0041 -0.0297 0 0.0041 0 0.0297;
0 0 0 0 1.09 -0.09 0 0 0 0 0 0;
0 0 0 0 0 0 0 0 0 0 0.5 0.5;
0 0 0 0 0 0 0 0 0 0 -0.375 1.375;
-1 0.2108 0 1 -0.35 0.1392 -0.9675 0.238 0 -0.0325 0 -0.238];
a=(sum(A~=0,2));
Row=find(a==max(a)).'
Gives:
Row =
1 5

更多回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by