Converting to array index
古いコメントを表示
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?
回答 (1 件)
Andrei Bobrov
2015 年 9 月 30 日
編集済み: Andrei Bobrov
2015 年 10 月 2 日
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 件のコメント
Walter Roberson
2015 年 10 月 2 日
Please attach a part of your file melbournewaterlevels.csv
Steven
2015 年 10 月 2 日
カテゴリ
ヘルプ センター および File Exchange で Dates and Time についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!