필터 지우기
필터 지우기

could anyone help me to solve the issue

조회 수: 1 (최근 30일)
jaah navi
jaah navi 2019년 6월 5일
답변: Rik 2019년 6월 5일
I am having a matrix size(4,8) which is having a combination of zero and non zero values.
could any one help me how to display the matrix in such a way that it should atleast contain one nonzero value with respect to its every row and every column
  댓글 수: 7
Matt J
Matt J 2019년 6월 5일
I need to modify the above matrix in such a way that every row and column should contain atleast one non zero value.
The original matrix you showed already did satisfy this requirement.
jaah navi
jaah navi 2019년 6월 5일
the values can be removed under the condition that every row and column should contain atleast one non zero values.

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

채택된 답변

Rik
Rik 2019년 6월 5일
This removes elements until your matrix is no longer valid according to your rule. It is very slow for bigger matrices, but it is guaranteed to work. Look up "bubble sort" if you want to understand how it works.
A=rand(4,8);
isValidMatrix=@(x) all(any(x,1)) && all(any(x,2));
B=A;
%use a structure similar to the 'bubble sort' algorithm
for idx1=1:numel(B)
for idx2=idx1:numel(B)
if B(idx2)==0,continue,end
B_temp=B;
B_temp(idx2)=0;
if isValidMatrix(B_temp)
B=B_temp;
end
end
end
disp(B)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by