我有一个9660 x 51的矩阵。第一列是日期。我使用datenum
转换日期,然后datestr
显示日期。但我想创建一个for循环,它将显示整个矩阵的日期和数据。
例如:
'12/31/11' '18:00' '9722' 'Millbrook' '13.05' '1.763' '1.14' '0.791' '1.589'
'12/31/11' '17:00' '9721' 'Millbrook' '13.03' '1.763' '1.138' '0.789' '1.58'
'12/31/11' '16:00' '9720' 'Millbrook' '12.98' '1.763' '1.138' '0.786' '1.565'
'12/31/11' '15:00' '9719' 'Millbrook' '13.14' '1.76' '1.138' '0.786' '1.555'
'12/31/11' '14:00' '9718' 'Millbrook' '13.13' '1.76' '1.138' '0.786' '1.558'
'12/31/11' '13:00' '9717' 'Millbrook' '13.19' '1.76' '1.135' '0.784' '1.567'
'12/31/11' '12:00' '9716' 'Millbrook' '13.16' '1.76' '1.133' '0.781' '1.594'
'12/31/11' '11:00' '9715' 'Millbrook' '13.15' '1.758' '1.133' '0.781' '1.626'
'12/31/11' '10:00' '9714' 'Millbrook' '13.1' '1.758' '1.13' '0.781' '1.663'
'12/31/11' '9:00' '9713' 'Millbrook' '12.81' '1.758' '1.13' '0.781' '1.689'
'12/31/11' '8:00' '9712' 'Millbrook' '12.81' '1.758' '1.13' '0.781' '1.697'
'12/31/11' '7:00' '9711' 'Millbrook' '13.02' '1.758' '1.133' '0.786' '1.699'
'12/31/11' '6:00' '9710' 'Millbrook' '13.02' '1.76' '1.138' '0.793' '1.707'
'12/31/11' '5:00' '9709' 'Millbrook' '13.02' '1.763' '1.143' '0.801' '1.719'
'12/31/11' '4:00' '9708' 'Millbrook' '13.03' '1.765' '1.145' '0.801' '1.729'
'12/31/11' '3:00' '9707' 'Millbrook' '13.03' '1.763' '1.143' '0.801' '1.741'
'12/31/11' '2:00' '9706' 'Millbrook' '13.03' '1.763' '1.143' '0.801' '1.748'
'12/31/11' '1:00' '9705' 'Millbrook' '13.04' '1.763' '1.143' '0.801' '1.753'
'12/31/11' '0:00' '9704' 'Millbrook' '13.04' '1.763' '1.14' '0.798' '1.763'
为了简化它,我希望能够在白天看整个矩阵。
感谢您的帮助:)
答案 0 :(得分:1)
您实际上不必将日期转换为按天分组。只需获取唯一日期并按照以下方式迭代它们:
myData = {
'12/31/11' '18:00' '9722' 'Millbrook' '13.05' '1.763' '1.14' '0.791' '1.589'
'12/31/11' '17:00' '9721' 'Millbrook' '13.03' '1.763' '1.138' '0.789' '1.58'
'12/31/11' '16:00' '9720' 'Millbrook' '12.98' '1.763' '1.138' '0.786' '1.565'
'12/31/11' '15:00' '9719' 'Millbrook' '13.14' '1.76' '1.138' '0.786' '1.555'
'12/31/11' '14:00' '9718' 'Millbrook' '13.13' '1.76' '1.138' '0.786' '1.558'
'12/31/11' '13:00' '9717' 'Millbrook' '13.19' '1.76' '1.135' '0.784' '1.567'
'12/31/11' '12:00' '9716' 'Millbrook' '13.16' '1.76' '1.133' '0.781' '1.594'
'12/31/11' '11:00' '9715' 'Millbrook' '13.15' '1.758' '1.133' '0.781' '1.626'
'12/31/11' '10:00' '9714' 'Millbrook' '13.1' '1.758' '1.13' '0.781' '1.663'
'12/31/11' '9:00' '9713' 'Millbrook' '12.81' '1.758' '1.13' '0.781' '1.689'
'12/31/11' '8:00' '9712' 'Millbrook' '12.81' '1.758' '1.13' '0.781' '1.697'
'12/31/11' '7:00' '9711' 'Millbrook' '13.02' '1.758' '1.133' '0.786' '1.699'
'12/31/11' '6:00' '9710' 'Millbrook' '13.02' '1.76' '1.138' '0.793' '1.707'
'12/31/11' '5:00' '9709' 'Millbrook' '13.02' '1.763' '1.143' '0.801' '1.719'
'12/31/11' '4:00' '9708' 'Millbrook' '13.03' '1.765' '1.145' '0.801' '1.729'
'12/31/11' '3:00' '9707' 'Millbrook' '13.03' '1.763' '1.143' '0.801' '1.741'
'12/31/11' '2:00' '9706' 'Millbrook' '13.03' '1.763' '1.143' '0.801' '1.748'
'12/31/11' '1:00' '9705' 'Millbrook' '13.04' '1.763' '1.143' '0.801' '1.753'
'12/31/11' '0:00' '9704' 'Millbrook' '13.04' '1.763' '1.14' '0.798' '1.763' };
uniqueDays = unique(myData(:,1));
for ind = 1:length(uniqueDays)
myDay = uniqueDays{ind};
logThisDay = strcmpi(myDay, myData(:,1));
thisDayData = myData(logThisDay,:);
disp(sprintf('********* DATA FOR %s *********', myDay));
disp(thisDayData(:, 2:end))
end