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

조회 수: 1 (최근 30일)
karan
karan 2011년 12월 19일
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