Converting to array index
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Okay so I am given a csv file with the a month, year and water level.
The first entry is January 1940 with say 50 water level and the last is 2015 august with 70 water level.
Now we are required to get a user to enter two different months and years and plot the water level between those two respective points. i.e for example between January 2000 and December 2000.
Now I imported all the data as follows:
Water = importdata('melbournewaterlevels.csv');
StrMonth = Water.textdata(2:end,2);
StrYear=Water.textdata(2:end,1);
WaterLevel = Water.data;
StrYear(1 : end, 1 : end);
Now prompting the user to enter there choice:
m1=input(' Please input Month 1: ');
y1=input(' Please input Year 1: ');
m2=input(' Please input Month 2: ');
y2=input(' Please input Year 2: ');
How can I get that for example to convert it into an index?
0 comentarios
Respuestas (1)
Andrei Bobrov
el 30 de Sept. de 2015
Editada: Andrei Bobrov
el 2 de Oct. de 2015
Please attach small part of the your file: melbournewaterlevels.csv.
date1 = [StrYear StrMonth];
level1 = Water.data;
ym1=input(' Please input first Year and Month as [Year, Month]: ');
ym2=input(' Please input last Year and Month as [Year, Month]: ');
l1 = datenum([ym1,1;ym2,1]);
d1 = datenum([date1,ones(size(date1,1),1)]);
out = WaterLevel(l1(1)>=d1 & l1(2)<=d1);
or
l1 = find(cumsum(ismember(date1, [ym1;ym2],'rows'))==1);
out = WaterLevel([l1;l1(end)+1]);
EDIT (after attaching of file)
Water = importdata('melbournewaterlevels.csv');
x = strcat(Water.textdata(2:end,1),Water.textdata(2:end,2));
d1 = datenum(x,'yyyymmm');
ym1=input(' Please input first Year and Month as [Year, Month]: ');
ym2=input(' Please input last Year and Month as [Year, Month]: ');
l1 = datenum([ym1,1;ym2,1]);
out = Water.data(l1(1)>=d1 & l1(2)<=d1);
or
[y,m] = datevec(d1);
l1 = find(cumsum(ismember([y,m], [ym1;ym2],'rows'))==1);
out = Water.data([l1;l1(end)+1]);
2 comentarios
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!