if loop that is not working properly, row should be deleted based on several criterias but do not
이전 댓글 표시
hi,
I have a matrix with 8 columns and I would like to delete those rows where the value of column 8 exceeds 1.1 or is below 0.9 and apply a similar criteria on column 5, here is the respective code:
while i < size(data8, 1)
i = i + 1 ;
if(data8(i,8)>1.1)
data8(i,:) = [];
elseif(data8(i,8)<0.9)
data8(i,:) = [];
elseif(data8(i,5)<5*1/365)
data8(i,:) = [];
elseif(data8(i,5)>120*1/365)
data8(i,:) = [];
end
end
although the code is running, I get in the resulting matrix values in column 8 that exceeds 1.1 and are below 0.9, whan do I need to change?
채택된 답변
추가 답변 (1개)
Locks
2013년 4월 13일
0 개 추천
댓글 수: 3
Image Analyst
2013년 4월 13일
편집: Image Analyst
2013년 4월 13일
This should have been a comment to my answer. | means "or" while & means "and". It tells you which rows should be removed from the original array. You might have to have
rowsToDelete = rowsToDelete8 | rowsToDelete5
instead of
rowsToDelete = rowsToDelete8 & rowsToDelete5
depending on exactly what criteria you're after.
Locks
2013년 4월 13일
Image Analyst
2013년 4월 13일
편집: Image Analyst
2013년 4월 13일
That's correct. If we're done, then mark my answer (not yours) as Accepted.
카테고리
도움말 센터 및 File Exchange에서 Performance and Memory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!