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

1 次查看(过去 30 天)
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.

采纳的回答

the cyclist
the cyclist 2011-12-19
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 个评论
karan
karan 2011-12-19
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,:)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by