Number to time of day conversion with datestr problem....

3 views (last 30 days)
karan
karan on 19 Dec 2011
Hi , I have an analysed data-set that I want to present the user.This data set has analysis for a time series data, therefore i have produced aggregated data for every 15 minutes.
Now since this has to be organised, i wanted to make colums of time periods of data that i want to illustrate. I used the following lines of code:
tp = 15/(24*60)
kilo = 1:(24*60/15);
l = datestr(kilo*tp,'HH:MM PM')
for first 5 points i get:::
l =
12:15 AM
12:30 AM
12:45 AM
1:00 AM
1:15 AM
Now the main problem is the accessibility with this new matrix l ..
%%%%%%%%%%%%%%%%
l(1:9)
ans =
111 2221
%%%%%%%%%%%%%%%%%
l(1)
ans =
1
%%%%%%%%%%%%
instead of the above answers i want l(1) to give me '12:15 AM' and not '1'
Thank you very much for your help in advance.

Accepted Answer

the cyclist
the cyclist on 19 Dec 2011
Your output "l" is a character array, of dimension 96x8. The first row of that array can be displayed with
>> l(1,:)
rather than
>> l(1)
which is only the first character.
The reason that l(1:9) gave the output that you saw is the MATLAB is pulling the first 9 characters going down the first column.
You could convert that character array to a 96x1 cell array, where each row will be put into one element of the cell array, using
>> timeCell = cellstr(l)
Then,
>> timeCell{1}
would be the entire first row. (Note the curly brackets in that last expression, which are used to access the contents of the cell, rather than the cell itself.)
  1 Comment
karan
karan on 19 Dec 2011
I was being really stupid here....I got it thanks for the explanation....
For the people who are going to view in future.The following code works
tp = 15/(24*60)
kilo = 1:((24*60)/15);
l = datestr(kilo*tp,'HH:MM PM');
timeCell = cellstr(l);
y = timeCell(kilo,:)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!