Converting to array index
Mostra commenti meno recenti
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?
Risposte (1)
Andrei Bobrov
il 30 Set 2015
Modificato: Andrei Bobrov
il 2 Ott 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 Commenti
Walter Roberson
il 2 Ott 2015
Please attach a part of your file melbournewaterlevels.csv
Steven
il 2 Ott 2015
Categorie
Scopri di più su Dates and Time in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!