Assign values to numbers and recount after a fixed interval
    10 次查看(过去 30 天)
  
       显示 更早的评论
    
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?
回答(2 个)
  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)
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
			
	产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


