how to select higher value in a matrix and change that by introducing an error?

조회 수: 2 (최근 30일)
I have a matrix,
a= [ 0.83 0.85 0.97 0.1 0.95 0.93 0.2 ; 0.2 0.12 0.12 0.76 0.77 0.78 0.25 ; 0.88 0.32 0.11 0.77 0.87 0.89 0.99]
by ceil(a) we get c matrix: c=[ 1 1 1 0 1 1 0 ; 0 0 0 1 1 1 0 ; 1 0 0 1 1 1 1]
now i want to introduce error position wise as err=1:3
so, at first err=1 will be introduced to first row where the only highest value is find in matrix a and 1 will become 0,same wise in 2nd row and 3rd row. Then err=2, that means the first two highest value is find and 1 will become zero, then same will be carried out for 2nd,3rd row. Next err=3...where 3 higher value will be changed.
please help me out asap....
plz plz plz.....
  댓글 수: 5
suchismita
suchismita 2014년 6월 2일
in sort() the position of matrix is changing...i want to identify the positions so that i can convert 1 to 0
Roger Wohlwend
Roger Wohlwend 2014년 6월 2일
Yes, but the sort command also tells you the original position of the sorted values (it's the second output variable). Use that information.

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

채택된 답변

George Papazafeiropoulos
George Papazafeiropoulos 2014년 6월 2일
Are you looking for something like this?
a= [ 0.83 0.85 0.97 0.1 0.95 0.93 0.2;
0.2 0.12 0.12 0.76 0.77 0.78 0.25;
0.88 0.32 0.11 0.77 0.87 0.89 0.99];
c=round(a)
for i=1:3
for err=1:3
[~,d]=sort(a(err,:),'descend');
a(err,d(1:i))=0;
end
end
cfinal=round(a)
I hope this will help!
  댓글 수: 3
suchismita
suchismita 2014년 6월 2일
sort is changing the 'a' matrix itself....but i dont want to disturb a matrix, the changes i want to make in c....as in matrix a in first row 0.97 is highest so that value in c will become zero same wise in 2nd row 0.77 (a(2,5)) will become zero, same process will be carried in 3rd row. In second round, first row will take the two highest numbers as 0.97 (1,3)and next highest to it is 0.95 (1,5) will become zero.... this is the concept....plz help me....
George Papazafeiropoulos
George Papazafeiropoulos 2014년 6월 2일
I think the following applies if you want the a matrix unaltered. The outer for loop (for i=1:3) is not required in this case, because for all i (=1,2,3) the maximum element of each row of A is selected and set to zero, so we can set i=3, select the three highest values, set them to zero and get rid of the initial i loop:
a= [ 0.83 0.85 0.97 0.1 0.95 0.93 0.2;
0.2 0.12 0.12 0.76 0.77 0.78 0.25;
0.88 0.32 0.11 0.77 0.87 0.89 0.99];
c=round(a)
for err=1:3
[~,d]=sort(a(err,:),'descend');
c(err,d(1:3))=0;
end

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

추가 답변 (1개)

suchismita
suchismita 2014년 6월 2일
thank u so much....ya i got it now....thank u so so so much...

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by