From: jay jay on
Hi,

I have a column matrix:

V = '09:30:00'
'09:30:03'
'09:30:05'
'09:30:09'
....

I want to convert it to seconds(from midnight), it is it should effectively become

34200
34203
34205
34209
....

(3600sec * 9.5hrs = 34200)

I can't think of a clever way to do it. It would be great if you could suggest a way to do it without using loops. The problem I have with loops is that my matrix is very huge and I have to do this exercise many times over, so loops would drastically hurt the efficiency of my program.

Much appreciated.

Thanks in advance :)
From: us on
"jay jay" <jay.oberoi(a)yahoo.com> wrote in message <i06o3s$cbl$1(a)fred.mathworks.com>...
> Hi,
>
> I have a column matrix:
>
> V = '09:30:00'
> '09:30:03'
> '09:30:05'
> '09:30:09'
> ...
>
> I want to convert it to seconds(from midnight), it is it should effectively become
>
> 34200
> 34203
> 34205
> 34209
> ...
>
> (3600sec * 9.5hrs = 34200)
>
> I can't think of a clever way to do it. It would be great if you could suggest a way to do it without using loops. The problem I have with loops is that my matrix is very huge and I have to do this exercise many times over, so loops would drastically hurt the efficiency of my program.
>
> Much appreciated.
>
> Thanks in advance :)

one of the solutions

t={
'09:30:00'
'09:30:03'
'09:30:05'
'09:30:09'
};
f=[3600,60,1];
r=datevec(t);
r=r(:,4:6)*f.';
disp(r);
%{
34200
34203
34205
34209
%}

us
From: TideMan on
On Jun 27, 6:27 pm, "us " <u...(a)neurol.unizh.ch> wrote:
> "jay jay" <jay.obe...(a)yahoo.com> wrote in message <i06o3s$cb...(a)fred.mathworks.com>...
> > Hi,
>
> > I have a column matrix:
>
> > V = '09:30:00'
> > '09:30:03'
> > '09:30:05'
> > '09:30:09'
> > ...
>
> > I want to convert it to seconds(from midnight), it is it should effectively become
>
> > 34200
> > 34203
> > 34205
> > 34209
> > ...
>
> > (3600sec * 9.5hrs = 34200)
>
> > I can't think of a clever way to do it. It would be great if you could suggest a way to do it without using loops. The problem I have with loops is that my matrix is very huge and I have to do this exercise many times over, so loops would drastically hurt the efficiency of my program.
>
> > Much appreciated.
>
> > Thanks in advance :)
>
> one of the solutions
>
>      t={
>           '09:30:00'
>           '09:30:03'
>           '09:30:05'
>           '09:30:09'
>      };
>      f=[3600,60,1];
>      r=datevec(t);
>      r=r(:,4:6)*f.';
>      disp(r);
> %{
>           34200
>           34203
>           34205
>           34209
> %}
>
> us

And here's another one:
tt=datenum(t);
r=round(86400*mod(tt,1));
From: jay jay on
TideMan <mulgor(a)gmail.com> wrote in message <bff167a7-48cc-48b2-bd19-8085977881a7(a)w9g2000prn.googlegroups.com>...
> On Jun 27, 6:27 pm, "us " <u...(a)neurol.unizh.ch> wrote:
> > "jay jay" <jay.obe...(a)yahoo.com> wrote in message <i06o3s$cb...(a)fred.mathworks.com>...
> > > Hi,
> >
> > > I have a column matrix:
> >
> > > V = '09:30:00'
> > > '09:30:03'
> > > '09:30:05'
> > > '09:30:09'
> > > ...
> >
> > > I want to convert it to seconds(from midnight), it is it should effectively become
> >
> > > 34200
> > > 34203
> > > 34205
> > > 34209
> > > ...
> >
> > > (3600sec * 9.5hrs = 34200)
> >
> > > I can't think of a clever way to do it. It would be great if you could suggest a way to do it without using loops. The problem I have with loops is that my matrix is very huge and I have to do this exercise many times over, so loops would drastically hurt the efficiency of my program.
> >
> > > Much appreciated.
> >
> > > Thanks in advance :)
> >
> > one of the solutions
> >
> >      t={
> >           '09:30:00'
> >           '09:30:03'
> >           '09:30:05'
> >           '09:30:09'
> >      };
> >      f=[3600,60,1];
> >      r=datevec(t);
> >      r=r(:,4:6)*f.';
> >      disp(r);
> > %{
> >           34200
> >           34203
> >           34205
> >           34209
> > %}
> >
> > us
>
> And here's another one:
> tt=datenum(t);
> r=round(86400*mod(tt,1));

Wonderful. Thanks a lot !