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!