How to delete/subtract/make zero all the values above a specific value?
조회 수: 3 (최근 30일)
이전 댓글 표시
My data has three columns. I want to do three things. 1) In the first analysis, I want to delete all the values above 255.
2)In the second analysis I want to make all the values above 255 to zero.
3)In the third analysis, I want just to take all the values above 255 and subtract 255 from it.
How can I do these. Please note that these all are not in a single analysis. These are three different analysis of a data.
I have tried the following:
index1 = find(Data(:,1)>=256&Data(:,2)<=256&Data(:,3)<=256);
Data(index1,:)=[]; %I think this can delete all above 255. But if I want to subtract by 255 and to replace with zeros, what should I do?
I am confused how to do in the second line! I know if I need to remove, I just need to replace Data-256 by []. But to make it zero and to subtract by 255, what should I do?
댓글 수: 0
채택된 답변
Sajjad Yazdani
2014년 4월 30일
For the first one use:
Data(Data(1,:)>255,:)=[];
For the second analysis :
Data(Data>255)=0;
And for last analysis :
Data(Data>255)=Data(Data>255)-255;
Remind that Logic indexing is more better than find() and more faster.
댓글 수: 0
추가 답변 (1개)
Andrei Bobrov
2014년 4월 30일
t = D > 255;
out1 = D(~t);
out2 = D;
out2(t) = 0;
out3 = D;
out3(t) = out3(t) - 255;
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Specialized Power Systems에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!