How to delete/subtract/make zero all the values above a specific value?

3 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Sajjad Yazdani
Sajjad Yazdani am 30 Apr. 2014
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.

Weitere Antworten (1)

Andrei Bobrov
Andrei Bobrov am 30 Apr. 2014
t = D > 255;
out1 = D(~t);
out2 = D;
out2(t) = 0;
out3 = D;
out3(t) = out3(t) - 255;

Kategorien

Mehr zu Specialized Power Systems finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by