Assign values to numbers and recount after a fixed interval

3 ビュー (過去 30 日間)
Hammad Khan
Hammad Khan 2020 年 2 月 18 日
回答済み: Steven Lord 2020 年 2 月 18 日
Hi.I have to assign number values to each day's each hour's precipitaton values. (starting from 1,end at 730 as the data is for two years). I want that the when the next day's 12:00am strikes it restarts counting from 2. e.g. And then when next year's date and time occur, it again gets a value of 1. Basically the values should be independent of the year.
Date Time Precipitation Values
1-1-1987 00:00 19 1
1-1-1987 01:00 19.2 1
.
.
1-1-1987 23:00 20 1
2-1-1987 00:00 25 2
.
.
12-31-1987 22:00 0.2 365
12-31-1987 23:00 0.4 365
.
.
1-1-1988 00:00 1.2 1
1-1-1988 01:00 3.4 1
Can anyone guide how to do this using loops?
  1 件のコメント
Stephen23
Stephen23 2020 年 2 月 18 日
Just add one to the 'Time' value.

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

回答 (2 件)

Murugan C
Murugan C 2020 年 2 月 18 日
consider excel as my input.
[numdata, textdata, rawdata] = xlsread('Test_data.xlsx');
timecolomn = (datestr( numdata(:,1), 'HH:MM' ));
for i = 1 : length(timecolomn)
g = strsplit(timecolomn(i,:),':');
if str2double(g{2}) == 0
value1{i} = str2double(g{1});
end
end
value_row = ['Values'; value1'];
rawdata = [rawdata value_row];
xlswrite('AddedValue.xlsx', rawdata)

Steven Lord
Steven Lord 2020 年 2 月 18 日
If your Date variable is a datetime array, call day on it asking for the 'dayofyear'.

カテゴリ

Help Center および File ExchangeTime Series Objects についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by