Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Help with importing Time stamp!!!

Subject: Help with importing Time stamp!!!

From: Vladimir V Bogachuk

Date: 19 Apr, 2012 22:31:17

Message: 1 of 5

hello
  I can't get MatLab to read this kind of data so then I can sort through it. Here is the sample of the data.
8/26/2011 13:09:04 PM 8/26/2011 13:09 Green JC Fall 2011
8/26/2011 13:09:08 PM 8/26/2011 13:09 Green JC Fall 2011
8/26/2011 13:09:13 PM 8/26/2011 13:09 Green JC Fall 2011
8/26/2011 13:09:19 PM 8/26/2011 13:09 Green JC Fall 2011
8/26/2011 13:09:21 PM 8/26/2011 13:09 NotSet JC Fall 2011

I used the [numData, textData, rawData] = xlsread('Ridership data1.xlsx',2);

'8/26/2011' 0.547962962962963 'PM' '8/26/2011' 0.547916666666667 'Green' 'JC' 'Fall 2011'

That's what i get, I can't get the time to import from Excel to the MatLab. Any help?


Thank you
Vlad

Subject: Help with importing Time stamp!!!

From: dpb

Date: 19 Apr, 2012 22:45:34

Message: 2 of 5

On 4/19/2012 5:31 PM, Vladimir V Bogachuk wrote:
> hello I can't get MatLab to read this kind of data so then I can sort
> through it. Here is the sample of the data.


> 8/26/2011 13:09:04 PM 8/26/2011 13:09 Green JC Fall 2011
...

> I used the [numData, textData, rawData] = xlsread('Ridership
> data1.xlsx',2);
>
> '8/26/2011' 0.547962962962963 'PM' '8/26/2011' 0.547916666666667 'Green'
> 'JC' 'Fall 2011'
>
> That's what i get, I can't get the time to import from Excel to the
> MatLab. Any help?


Oh, but you did...you just don't recognize it.

 >> t=(13+9/60+4/3600)/24;
 >> num2str(t,15)
ans =
0.547962962962963
 >>

--

Subject: Help with importing Time stamp!!!

From: TideMan

Date: 19 Apr, 2012 22:48:57

Message: 3 of 5

On Friday, April 20, 2012 10:31:17 AM UTC+12, Vladimir V Bogachuk wrote:
> hello
> I can't get MatLab to read this kind of data so then I can sort through it. Here is the sample of the data.
> 8/26/2011 13:09:04 PM 8/26/2011 13:09 Green JC Fall 2011
> 8/26/2011 13:09:08 PM 8/26/2011 13:09 Green JC Fall 2011
> 8/26/2011 13:09:13 PM 8/26/2011 13:09 Green JC Fall 2011
> 8/26/2011 13:09:19 PM 8/26/2011 13:09 Green JC Fall 2011
> 8/26/2011 13:09:21 PM 8/26/2011 13:09 NotSet JC Fall 2011
>
> I used the [numData, textData, rawData] = xlsread('Ridership data1.xlsx',2);
>
> '8/26/2011' 0.547962962962963 'PM' '8/26/2011' 0.547916666666667 'Green' 'JC' 'Fall 2011'
>
> That's what i get, I can't get the time to import from Excel to the MatLab. Any help?
>
>
> Thank you
> Vlad

The easiest way is to convert the times in Excel to numerical data - highlight the column, right click and Format Cells, then choose Number and increase the decimal places. When you import to Matlab you must add 693960 to get Matlab days.
There are other more complicated ways, but maybe this simple solution is right for you.

Subject: Help with importing Time stamp!!!

From: Vladimir V Bogachuk

Date: 19 Apr, 2012 23:16:35

Message: 4 of 5

dpb <none@non.net> wrote in message <jmq4ig$o4h$1@speranza.aioe.org>...
> On 4/19/2012 5:31 PM, Vladimir V Bogachuk wrote:
> > hello I can't get MatLab to read this kind of data so then I can sort
> > through it. Here is the sample of the data.
>
>
> > 8/26/2011 13:09:04 PM 8/26/2011 13:09 Green JC Fall 2011
> ...
>
> > I used the [numData, textData, rawData] = xlsread('Ridership
> > data1.xlsx',2);
> >
> > '8/26/2011' 0.547962962962963 'PM' '8/26/2011' 0.547916666666667 'Green'
> > 'JC' 'Fall 2011'
> >
> > That's what i get, I can't get the time to import from Excel to the
> > MatLab. Any help?
>
>
> Oh, but you did...you just don't recognize it.
>
> >> t=(13+9/60+4/3600)/24;
> >> num2str(t,15)
> ans =
> 0.547962962962963
> >>
>
> --
Thank you for your response, but how do i just get the actual time?


Thank you

Vlad

Subject: Help with importing Time stamp!!!

From: dpb

Date: 20 Apr, 2012 00:07:13

Message: 5 of 5

On 4/19/2012 6:16 PM, Vladimir V Bogachuk wrote:
> dpb <none@non.net> wrote in message <jmq4ig$o4h$1@speranza.aioe.org>...
>> On 4/19/2012 5:31 PM, Vladimir V Bogachuk wrote:
>> > hello I can't get MatLab to read this kind of data so then I can sort
>> > through it. Here is the sample of the data.
>>
>>
>> > 8/26/2011 13:09:04 PM 8/26/2011 13:09 Green JC Fall 2011
>> ...
>>
...

>> Oh, but you did...you just don't recognize it.
>>
>> >> t=(13+9/60+4/3600)/24;
>> >> num2str(t,15)
>> ans =
>> 0.547962962962963
>> >>
> Thank you for your response, but how do i just get the actual time?
...

That is "actual time" in datenum format. If you want the string
representation,

 > datestr(t,13)
ans =
13:09:04> datestr(t,14)
ans =
  1:09:04 PM
 >> datestr(t,16)
ans =
  1:09 PM
 >

Choose your desired format

As Tideman says, if you want to sort or select on date/time, the easiest
is to convert to datenum and manipulate that and the use datestr to
format if needed/desired.

If you have the returned string for the date and the column of
fractional days for the timestamp as you do, for example--

 >> tstr='8/26/2011'
tstr =
8/26/2011
 >> dn=datenum(tstr)
dn =
       734741
 >> datestr(dn+t,0)
ans =
26-Aug-2011 13:09:04
 >>

doc datestr
doc datenum

to learn all about date numbers.

--

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us