필터 지우기
필터 지우기

Which row has the minimum non zero element?

조회 수: 1 (최근 30일)
Giannakis Stoukas
Giannakis Stoukas 2015년 3월 21일
댓글: Star Strider 2015년 3월 21일
Hello i have a matrix and i want to find which is the row with minimum nonzeros elements.I dont want the number of non zeros,but i want to know which is the row.

채택된 답변

Star Strider
Star Strider 2015년 3월 21일
I’m not certain what you mean by ‘minimum nonzeros elements’. This takes the row sum of the rows with nonzero elements and finds the row with the smallest row sum:
M = randi(51, 20, 5)-1;
[r0,~] = find(M == 0);
Mnz = M(setdiff([1:size(M,1)],r0),:);
[Mu, ix] = sort(sum(M,2));
Row_min_nz = is(x); % Row With Minimum Row Sum
  댓글 수: 2
Giannakis Stoukas
Giannakis Stoukas 2015년 3월 21일
Ι forgot to write the word sum.Thank you
Star Strider
Star Strider 2015년 3월 21일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Jan
Jan 2015년 3월 21일
M = randi(5, 6, 6) - 1;
[V, Index] = min(sum(M == 0, 2));

Konstantinos Sofos
Konstantinos Sofos 2015년 3월 21일
a = [2,2,3;0,2,5;1 2 3]
[row,column]=find(a==min(min(a(a>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