0

I have a matrix that is 9660 x 51. The first column is dates. I used datenum to convert the dates and then datestr to display the dates. But I want to create a for loop that will display the dates and the data from the entire matrix.

For example:

'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' 

To simplify it I want to be able to look at the whole entire matrix but by day.

Thanks for the help :)

1 Answer 1

1

You don't really have to convert the dates to group them by day. Just get the unique dates and iterate over them like this:

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.