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?

채택된 답변

Sajjad Yazdani
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.

추가 답변 (1개)

Andrei Bobrov
Andrei Bobrov 2014년 4월 30일
t = D > 255;
out1 = D(~t);
out2 = D;
out2(t) = 0;
out3 = D;
out3(t) = out3(t) - 255;

카테고리

Help CenterFile Exchange에서 Specialized Power Systems에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by