How to take value of particular interval from a column?

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

 Respuesta aceptada

a(a(:,1)>800 & a(:,1)<1000,1)=nan

2 comentarios

result is not coming How can I?
How can I improve my result ? result is not coming ? 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 a(a(i,1)>800 & a(i,1)<1000,1)=NaN;
a(i,1)=NaN;
k=k+1;
end
end
How can I improve result?
Azzi Abdelmalek
Azzi Abdelmalek el 18 de Ag. de 2013
Editada: Azzi Abdelmalek el 18 de Ag. de 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

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 18 de Ag. de 2013
Editada: Image Analyst el 18 de Ag. de 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 comentarios

RS
RS el 18 de Ag. de 2013
Editada: RS el 18 de Ag. de 2013
How can I improve my result ? result is not coming ? 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
Andrei Bobrov
Andrei Bobrov el 18 de Ag. de 2013
Editada: Andrei Bobrov el 18 de Ag. de 2013
a(a(:,1) <= 600 | a(:,1) >= 800,1) = nan;
or
a(a(:,1) <= 600 | a(:,1) >= 800,:) = nan;
if a(a(:,1) <= 600 | a(:,1) >= 800,1) = nan;
|
Error: The expression to the left of the equals sign is not a valid target for an
assignment.
How can I improve?
all your code
a=xlsread('Book1.xlsx');
a(a(:,1) <= 600 | a(:,1) >= 800,1) = nan;
Image Analyst
Image Analyst el 18 de Ag. de 2013
Editada: Image Analyst el 18 de Ag. de 2013
You can improve it by using the code I gave you. You seemed to totally ignore it. First of all, you don't have any rows where a value in the range 600 to 800 is in column 1. So there's nothing to take out of it. I don't know why you are testing a matrix that does not have the condition you are looking for. So I took your data and made the 80 into 800 so I would have at least one row that fits your criteria. Then look at this code:
data=[...
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
800 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]
column = 1; % This is the column we want to check values of.
rowIndexesInRange = data(:, column) >= 600 & data(:, column) <= 800
extractedValues = data(rowIndexesInRange , :)
And look at the result:
extractedValues = 800 4.8635 14.017 0.08093 308.61322
RS
RS el 18 de Ag. de 2013
In that row all element should be NaN? How can I?
Image Analyst
Image Analyst el 18 de Ag. de 2013
Editada: Image Analyst el 18 de Ag. de 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.)

Iniciar sesión para comentar.

Categorías

Etiquetas

Preguntada:

RS
el 18 de Ag. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by