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

2 Ansichten (letzte 30 Tage)
karan
karan am 19 Dez. 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.

Akzeptierte Antwort

the cyclist
the cyclist am 19 Dez. 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 Kommentar
karan
karan am 19 Dez. 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,:)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by