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:
sampling time from seconds to ms

Subject: sampling time from seconds to ms

From: fmri

Date: 21 Jun, 2013 21:00:08

Message: 1 of 8

Hi all,

if I have a vector that contains 60 elements or values. these are time in seconds.
So something like this:
0
1
3
4
6
8
9
20
..
.
.
450

What I am trying to do is to return a vector that is represented in millsecons so if I have say a 3 seconds and I want to represent as 0.5 then the 3 s becomes 0.5 0.5 0.5 0.5 0.5 0.5.

Is this possible ?

Thanks

AS

Subject: sampling time from seconds to ms

From: fmri

Date: 21 Jun, 2013 21:14:08

Message: 2 of 8

"fmri" wrote in message <kq2eso$fi0$1@newscl01ah.mathworks.com>...
> Hi all,
>
> if I have a vector that contains 60 elements or values. these are time in seconds.
> So something like this:
> 0
> 1
> 3
> 4
> 6
> 8
> 9
> 20
> ..
> .
> .
> 450
>
> What I am trying to do is to return a vector that is represented in millsecons so if I have say a 3 seconds and I want to represent as 0.5 then the 3 s becomes 0.5 0.5 0.5 0.5 0.5 0.5.
>
> Is this possible ?
>
> Thanks
>
> AS


a simple manual example :
3
10
16
new one= [ 3:0.05:7,10:0.05:13,16:0.05:19]

so I want to do this for the whole vector

Thanks

Subject: sampling time from seconds to ms

From: TideMan

Date: 21 Jun, 2013 23:29:11

Message: 3 of 8

On Saturday, June 22, 2013 9:14:08 AM UTC+12, fmri wrote:
> "fmri" wrote in message <kq2eso$fi0$1@newscl01ah.mathworks.com>...
>
> > Hi all,
>
> >
>
> > if I have a vector that contains 60 elements or values. these are time in seconds.
>
> > So something like this:
>
> > 0
>
> > 1
>
> > 3
>
> > 4
>
> > 6
>
> > 8
>
> > 9
>
> > 20
>
> > ..
>
> > .
>
> > .
>
> > 450
>
> >
>
> > What I am trying to do is to return a vector that is represented in millsecons so if I have say a 3 seconds and I want to represent as 0.5 then the 3 s becomes 0.5 0.5 0.5 0.5 0.5 0.5.
>
> >
>
> > Is this possible ?
>
> >
>
> > Thanks
>
> >
>
> > AS
>
>
>
>
>
> a simple manual example :
>
> 3
>
> 10
>
> 16
>
> new one= [ 3:0.05:7,10:0.05:13,16:0.05:19]
>
>
>
> so I want to do this for the whole vector
>
>
>
> Thanks

I'm afraid that even after reading both your posts several times, I have NO IDEA what you are getting at.
You talk about milliseconds (thousandths of a second), then say you want to divide 3 s into intervals of 0.5 s (i.e. 500 milliseconds).
And how you get this:
> new one= [ 3:0.05:7,10:0.05:13,16:0.05:19]
from 3 10 16 is a complete mystery to me.

To get help, you need to explain things better.

Subject: sampling time from seconds to ms

From: fmri

Date: 22 Jun, 2013 00:16:13

Message: 4 of 8

TideMan <mulgor@gmail.com> wrote in message <082d6aa7-0852-43c7-8dd4-e16b596c400a@googlegroups.com>...
> On Saturday, June 22, 2013 9:14:08 AM UTC+12, fmri wrote:
> > "fmri" wrote in message <kq2eso$fi0$1@newscl01ah.mathworks.com>...
> >
> > > Hi all,
> >
> > >
> >
> > > if I have a vector that contains 60 elements or values. these are time in seconds.
> >
> > > So something like this:
> >
> > > 0
> >
> > > 1
> >
> > > 3
> >
> > > 4
> >
> > > 6
> >
> > > 8
> >
> > > 9
> >
> > > 20
> >
> > > ..
> >
> > > .
> >
> > > .
> >
> > > 450
> >
> > >
> >
> > > What I am trying to do is to return a vector that is represented in millsecons so if I have say a 3 seconds and I want to represent as 0.5 then the 3 s becomes 0.5 0.5 0.5 0.5 0.5 0.5.
> >
> > >
> >
> > > Is this possible ?
> >
> > >
> >
> > > Thanks
> >
> > >
> >
> > > AS
> >
> >
> >
> >
> >
> > a simple manual example :
> >
> > 3
> >
> > 10
> >
> > 16
> >
> > new one= [ 3:0.05:7,10:0.05:13,16:0.05:19]
> >
> >
> >
> > so I want to do this for the whole vector
> >
> >
> >
> > Thanks
>
> I'm afraid that even after reading both your posts several times, I have NO IDEA what you are getting at.
> You talk about milliseconds (thousandths of a second), then say you want to divide 3 s into intervals of 0.5 s (i.e. 500 milliseconds).
> And how you get this:
> > new one= [ 3:0.05:7,10:0.05:13,16:0.05:19]
> from 3 10 16 is a complete mystery to me.
>
> To get help, you need to explain things better.


I am really sorry you are absolutely right. I wrote this while I without even reading it.

So your point about dividing the 3 seconds into intervals of 0.5 or 0.25 or n is correct.
For example this is the beginning of the vector that I have:
0
5
10
16
20
26

Each of these represents the beginning ( onset ) of something that lasts for 3 seconds. Now What I want is to make this vector as an interval so this is what I am hoping to get:
0
0.5
1
1.5
2
2.5
3
5
5.5
6
6.5
7
7.5
8
.
.
.
.
So TO do it manually I could do this
[ 0:0.5:3,5:0.5:8,10:0.5,13,16:0.5:19]

But I think there must be a way of doing this by naming the vector and its content.
For example : [ each element in x :0.5: each element in x + 3 ]

I hope I explain it better now:-)

Subject: sampling time from seconds to ms

From: dpb

Date: 22 Jun, 2013 01:09:23

Message: 5 of 8

On 6/21/2013 7:16 PM, fmri wrote:
...

> For example this is the beginning of the vector that I have:
> 0
> 5
> 10
> 16
> 20
> 26
>
> Each of these represents the beginning ( onset ) of something that lasts
> for 3 seconds. Now What I want is to make this vector as an interval so
> this is what I am hoping to get:
> 0
> 0.5
> 1
...

> ..
> ..
> So TO do it manually I could do this [ 0:0.5:3,5:0.5:8,10:0.5,13,16:0.5:19]
>
> But I think there must be a way of doing this by naming the vector and
> its content.
...

Well, brute force and not elegant at all (but nothing really clever
leapt out at me at the moment and it's getting late in the day so I'm
not thinking too much... :) )

 >> v
v =
      0
      5
     10
     16
     20
 >> V=[];for i=1:length(v)-1,V=[V v(i):0.5:v(i+1)-0.5];end;V
V =
   Columns 1 through 10
          0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000
    3.5000 4.0000 4.5000
   Columns 11 through 20
     5.0000 5.5000 6.0000 6.5000 7.0000 7.5000 8.0000
    8.5000 9.0000 9.5000
   Columns 21 through 30
    10.0000 10.5000 11.0000 11.5000 12.0000 12.5000 13.0000
   13.5000 14.0000 14.5000
   Columns 31 through 40
    15.0000 15.5000 16.0000 16.5000 17.0000 17.5000 18.0000
   18.5000 19.0000 19.5000
   Column 41
    20.0000
 >>

--

Subject: sampling time from seconds to ms

From: fmri

Date: 22 Jun, 2013 09:44:13

Message: 6 of 8

dpb <none@non.net> wrote in message <kq2tfk$8d9$1@speranza.aioe.org>...
> On 6/21/2013 7:16 PM, fmri wrote:
> ...
>
> > For example this is the beginning of the vector that I have:
> > 0
> > 5
> > 10
> > 16
> > 20
> > 26
> >
> > Each of these represents the beginning ( onset ) of something that lasts
> > for 3 seconds. Now What I want is to make this vector as an interval so
> > this is what I am hoping to get:
> > 0
> > 0.5
> > 1
> ...
>
> > ..
> > ..
> > So TO do it manually I could do this [ 0:0.5:3,5:0.5:8,10:0.5,13,16:0.5:19]
> >
> > But I think there must be a way of doing this by naming the vector and
> > its content.
> ...
>
> Well, brute force and not elegant at all (but nothing really clever
> leapt out at me at the moment and it's getting late in the day so I'm
> not thinking too much... :) )
>
> >> v
> v =
> 0
> 5
> 10
> 16
> 20
> >> V=[];for i=1:length(v)-1,V=[V v(i):0.5:v(i+1)-0.5];end;V
> V =
> Columns 1 through 10
> 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000
> 3.5000 4.0000 4.5000
> Columns 11 through 20
> 5.0000 5.5000 6.0000 6.5000 7.0000 7.5000 8.0000
> 8.5000 9.0000 9.5000
> Columns 21 through 30
> 10.0000 10.5000 11.0000 11.5000 12.0000 12.5000 13.0000
> 13.5000 14.0000 14.5000
> Columns 31 through 40
> 15.0000 15.5000 16.0000 16.5000 17.0000 17.5000 18.0000
> 18.5000 19.0000 19.5000
> Column 41
> 20.0000
> >>
>
> --

Thanks for this

the only problem is that I do not want it to do it from 0 to 20 rather for each element.
so if I have v = [ 0 , 3 , 8 , 15 ]
I want v = [ 0 , 0.5 , 1 , 1.5 , 2 , 2.5 , 3 , 3.5 , 4 , 4.5 ,5 , 5.5 ,6 , 8 , 8.5 , 9 , 9.5 ,10, 10.5 , 11, 15, 15.5,16,16.5,17,17.5,18 .....]

notice that it is doing this for the exact element in v and not including for example 6.5,7 , 12,12.5,13,13.5,14,14.5

I hope this is more clear now

Subject: sampling time from seconds to ms

From: Marc

Date: 22 Jun, 2013 12:49:06

Message: 7 of 8

"fmri" wrote in message <kq3rld$ja1$1@newscl01ah.mathworks.com>...
> dpb <none@non.net> wrote in message <kq2tfk$8d9$1@speranza.aioe.org>...
> > On 6/21/2013 7:16 PM, fmri wrote:
> > ...
> >
> > > For example this is the beginning of the vector that I have:
> > > 0
> > > 5
> > > 10
> > > 16
> > > 20
> > > 26
> > >
> > > Each of these represents the beginning ( onset ) of something that lasts
> > > for 3 seconds. Now What I want is to make this vector as an interval so
> > > this is what I am hoping to get:
> > > 0
> > > 0.5
> > > 1
> > ...
> >
> > > ..
> > > ..
> > > So TO do it manually I could do this [ 0:0.5:3,5:0.5:8,10:0.5,13,16:0.5:19]
> > >
> > > But I think there must be a way of doing this by naming the vector and
> > > its content.
> > ...
> >
> > Well, brute force and not elegant at all (but nothing really clever
> > leapt out at me at the moment and it's getting late in the day so I'm
> > not thinking too much... :) )
> >
> > >> v
> > v =
> > 0
> > 5
> > 10
> > 16
> > 20
> > >> V=[];for i=1:length(v)-1,V=[V v(i):0.5:v(i+1)-0.5];end;V
> > V =
> > Columns 1 through 10
> > 0 0.5000 1.0000 1.5000 2.0000 2.5000 3.0000
> > 3.5000 4.0000 4.5000
> > Columns 11 through 20
> > 5.0000 5.5000 6.0000 6.5000 7.0000 7.5000 8.0000
> > 8.5000 9.0000 9.5000
> > Columns 21 through 30
> > 10.0000 10.5000 11.0000 11.5000 12.0000 12.5000 13.0000
> > 13.5000 14.0000 14.5000
> > Columns 31 through 40
> > 15.0000 15.5000 16.0000 16.5000 17.0000 17.5000 18.0000
> > 18.5000 19.0000 19.5000
> > Column 41
> > 20.0000
> > >>
> >
> > --
>
> Thanks for this
>
> the only problem is that I do not want it to do it from 0 to 20 rather for each element.
> so if I have v = [ 0 , 3 , 8 , 15 ]
> I want v = [ 0 , 0.5 , 1 , 1.5 , 2 , 2.5 , 3 , 3.5 , 4 , 4.5 ,5 , 5.5 ,6 , 8 , 8.5 , 9 , 9.5 ,10, 10.5 , 11, 15, 15.5,16,16.5,17,17.5,18 .....]
>
> notice that it is doing this for the exact element in v and not including for example 6.5,7 , 12,12.5,13,13.5,14,14.5
>
> I hope this is more clear now

So just change the v(i+1) - 0.5 to v(i)+3 for the interval length you desire, correct?

Subject: sampling time from seconds to ms

From: dpb

Date: 22 Jun, 2013 13:08:58

Message: 8 of 8

On 6/22/2013 4:44 AM, fmri wrote:
> dpb <none@non.net> wrote in message <kq2tfk$8d9$1@speranza.aioe.org>...
...

>> Well, brute force and not elegant at all (but nothing really clever
>> leapt out at me at the moment and it's getting late in the day so I'm
>> not thinking too much... :) )
>>
>> >> v
>> v =
>> 0
>> 5
>> 10
>> 16
>> 20
>> >> V=[];for i=1:length(v)-1,V=[V v(i):0.5:v(i+1)-0.5];end;V
...

> the only problem is that I do not want it to do it from 0 to 20 rather
> for each element.
> so if I have v = [ 0 , 3 , 8 , 15 ]
> I want v = [ 0 , 0.5 , 1 , 1.5 , 2 , 2.5 , 3 , 3.5 , 4 , 4.5 ,5 , 5.5 ,6
> , 8 , 8.5 , 9 , 9.5 ,10, 10.5 , 11, 15, 15.5,16,16.5,17,17.5,18 .....]
>
> notice that it is doing this for the exact element in v and not
> including for example 6.5,7 , 12,12.5,13,13.5,14,14.5
> I hope this is more clear now

V=[];for i=1:length(v),V=[V v(i):0.5:v(i)+3];end

Salt to suit...


--

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