Info

This question is closed. Reopen it to edit or answer.

Need help with making date string or vector from matrix data

1 view (last 30 days)
I have a long series of time averaging data in a matrix where column one is the month, column two is the day, column three is the year and column four is the hour--columns five and six are the time averaged data.
I want to combine the first four columns in to a date vector that I can subsequently use to graph the data chronologically and to use for descriptive statistics. How do I combine these?

Answers (2)

Kate Roberts
Kate Roberts on 8 Mar 2012
Are all of the date objectifiers numbers? If so then you could turn them into a string using string concatenate and num2str.
ie date = strcat(num2str(month),'/',num2str(day),'/',num2str(year),' Hour: ', num2str(hour));
As for the vector why not combine date to be a certain number ie 3/7/12 4pm (16:00 military) then the date becomes 30716 (Note: I ignored the year). Then you could sort by the size of the number.
-K

Walter Roberson
Walter Roberson on 8 Mar 2012
timenums = datenum([Matrix(:,3) Matrix(:,1) Matrix(:,2) Matrix(:,4) zeros(size(Matrix,1),2)]);
The result will be serial date numbers, which can be sorted, and can be used as axis coordinates in conjunction with the datetick() routine.
The zeros() are to fill in the minute and second, as date vectors are recognized with 3 elements (Y M D) or 6 elements (Y M D H M S)

Community Treasure Hunt

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

Start Hunting!