Assign values to numbers and recount after a fixed interval

1 view (last 30 days)
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?

Answers (2)

Murugan C
Murugan C on 18 Feb 2020
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 on 18 Feb 2020
If your Date variable is a datetime array, call day on it asking for the 'dayofyear'.

Tags

Products

Community Treasure Hunt

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

Start Hunting!