How to take value of particular interval from a column?
2 views (last 30 days)
Show older comments
there is column having arbitrary value from 0-1200 but I have to take only 600-800 from that column? How can I ?
1100 4.7693 13.746 0.08116 308.6983
1160 4.5938 13.24 0.08112 308.68619
1220 4.5577 13.136 0.08109 308.67407
1280 4.9122 14.158 0.08105 308.66205
1340 5.0029 14.419 0.08102 308.64944
1400 4.7408 13.664 0.08099 308.63684
20 4.7447 13.675 0.08096 308.62524
80 4.8635 14.017 0.08093 308.61322
140 4.7867 13.796 0.0809 308.60065
200 4.6726 13.467 0.08088 308.58905
260 4.7121 13.581 0.08086 308.57675
320 4.6942 13.529 0.08083 308.56442
a=xlsread('Book1.xlsx');
k=1;
for i=1:length(a(:,1))
if 600<=a(i,1)>=800
a(i,1)=NaN;
k=k+1;
end
end
0 Comments
Accepted Answer
Azzi Abdelmalek
on 18 Aug 2013
a(a(:,1)>800 & a(:,1)<1000,1)=nan
2 Comments
Azzi Abdelmalek
on 18 Aug 2013
Edited: Azzi Abdelmalek
on 18 Aug 2013
a=xlsread('Book1.xlsx');
k=1;
for i=1:numel(a(:,1))
if a(i,1)>800 & a(i,1)<1000
a(i,1)=nan;
end
end
More Answers (1)
Image Analyst
on 18 Aug 2013
Edited: Image Analyst
on 18 Aug 2013
To extract elements in that range to a new array, try this:
rowIndexesInRange = data(:, column) >= 600 & data(:, column) <= 800;
extractedValues = data(rowIndexesInRange , column);
Note: extractedValues will probably be a smaller size than data. If you want the elements in the same locations but just want others set to zero or some other value, then you'll have to set do
data(~rowIndexesInRange, :) = 0;
This will just zero out elements not in the range and leave elements in range in their original location.
7 Comments
Image Analyst
on 18 Aug 2013
Edited: Image Analyst
on 18 Aug 2013
If "take" means "set to nan" for you (though that seems like a strange definition of take to me), then do this:
data(~rowIndexesInRange, :) = nan;
result will be in data, rather than extractedValues. )You will probably also need cell2mat to turn your cell array from xlsread() into a matrix.)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!