Dear colleagues I have excel file to show rainfall in each minute. I would have rainfall in hourly, daily and monthly. It means that i need to sum each hour to show hourly (cumulative). and sum each day to show daily and each month for showing monthly rainfall (cumulative). I read some codes from internet but i cant run them. I am new in matlab and I need to do this job. I attached the excel file as small sample but my data are growing each day.

 採用された回答

Andrei Bobrov
Andrei Bobrov 2016 年 5 月 25 日
編集済み: Andrei Bobrov 2016 年 5 月 30 日

1 投票

data = xlsread('rain.xlsx');
[y,mm,d,h,m] = datevec(data(:,1) + datenum([1900 0 0]) - 1);
cum_minutes = [y,mm,d,h,m, cumsum(m)];
[hy,~,hc] = unique([y,mm,d,h],'rows');
cum_hourly = [hy, cumsum(accumarray(hc,data(:,2)))];
[dy,~,dc] = unique([y,mm,d],'rows');
cum_daily = [dy, cumsum(accumarray(dc,data(:,2)))];
[mhy,~,mhc] = unique([y,mm],'rows');
cum_monthly = [mhy, cumsum(accumarray(mhc,data(:,2)))];

7 件のコメント

Milad
Milad 2016 年 5 月 25 日
Hi Andrei Thanks for your help. I performed commands. I receive an error on second command or second line. I don't know why. do you think it is related with my data which are one month and half. If you need a complete month let me know. I made it as sample. i attached an image.
Andrei Bobrov
Andrei Bobrov 2016 年 5 月 25 日
I am corrected. Please try it.
Milad
Milad 2016 年 5 月 27 日
Hi Andrei, thanks for your collaboration. Indeed, I tried to run the command from yesterday and find a solution without taking your time. But, it is still stick in reading time format. MATLAB is not good to read date time format I think. I changed format first column to number in excel. it means all dates time returned to a number in excel. do u think it is easier to have command for this format and get rid out from error. I attached for you an excel(similar as before) with two months January and February complete. first column is date but returned to number format in excel and second column is rain has general format.I am so appreciated the you let me know your solution. also, I attached the new error for you when I perform the second line of command.
Andrei Bobrov
Andrei Bobrov 2016 年 5 月 27 日
New first two rows in my code:
data = xlsread('rain.xlsx');
[y,mm,d,h,m] = datevec(data(:,1) + datenum([1900 0 0]) - 1);
Milad
Milad 2016 年 5 月 30 日
Hi Andrei.
I passed the error so thankful, but I could not solve the second error which is same for 3 commands. I attached for you an image. I hope I can pass this error as last one. So, thankful for your spending your time on this.
Andrei Bobrov
Andrei Bobrov 2016 年 5 月 30 日
Corrected.
Milad
Milad 2016 年 6 月 3 日
hi Andrei Hope you re fine. thanks for you previous codes. May I have request from you..... if you are free ...... I attached previous file and i would do a revision on it to show data for each hour, day, month.I make a small sample in excel in sheet 2 just for two hour and two day and two months for you to show my subject. do you think, can revise the our commands for that sample. cheers

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTime Series Events についてさらに検索

質問済み:

2016 年 5 月 25 日

コメント済み:

2016 年 6 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by