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

1 次查看(过去 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