make zero some rows of a matrix

조회 수: 2 (최근 30일)
mohammad
mohammad 2011년 9월 17일
It's neede to make zero those rows of a matrix that matrix(i,2) is 2 value less than matrix(1,2). 'matrix' has 2 column and 10000 rows. I wrote this but i don't know for what doesn't work
for i=1:size(r,1)
if r(i,2)-r(1,2)<2
r(i,2)=0;
end
end
  댓글 수: 2
Wayne King
Wayne King 2011년 9월 17일
I'm not sure I understand the condition you want to test correctly, because assume that r(1,2)=6 and r(i,2)=5 for some i not equal to 1. Then,
r(i,2)-r(1,2)<1 is true (5-6 < 1), but r(i,2) is not "2 value less than r(1,2)".
So what exactly do you want to test?
mohammad
mohammad 2011년 9월 17일
edit
sorry there was a typing wrong

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

채택된 답변

Andrei Bobrov
Andrei Bobrov 2011년 9월 17일
r(r(1,2)-r(:,2)>=2,:) = 0
  댓글 수: 2
mohammad
mohammad 2011년 9월 17일
really nice
thanks
mohammad
mohammad 2011년 9월 17일
i don't know but when i equal a=r(1,2) and use a instead of r(1,2), matlab works!

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

추가 답변 (0개)

카테고리

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