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:
easy lil question (when you know how!)

Subject: easy lil question (when you know how!)

From: Dave

Date: 6 Apr, 2009 20:47:01

Message: 1 of 10

Hi!

I need to make a column of about 8000 values that simply alternates between one value and another, it needs to be 0 then 12 then 0 then 12... and so on.

Can you help me out (pretty) please!

THANKS!

Dave

Subject: easy lil question (when you know how!)

From: Matt Fig

Date: 6 Apr, 2009 20:59:02

Message: 2 of 10

V = zeros(10,1); % Resize as needed.
V(2:2:end) = 12

Subject: easy lil question (when you know how!)

From: TideMan

Date: 6 Apr, 2009 21:01:11

Message: 3 of 10

On Apr 7, 8:47=A0am, "Dave " <yogi_c...@yahoo.com> wrote:
> Hi!
>
> I need to make a column of about 8000 values that simply alternates betwe=
en one value and another, it needs to be 0 then 12 then 0 then 12... and so=
 on.
>
> Can you help me out (pretty) please!
>
> THANKS!
>
> Dave

y=3D[zeros(1,4000);12*ones(1,4000)];
y=3Dy(:)

Subject: easy lil question (when you know how!)

From: someone

Date: 6 Apr, 2009 21:06:02

Message: 4 of 10

"Dave " <yogi_cave@yahoo.com> wrote in message <grdpo4$lvm$1@fred.mathworks.com>...
> Hi!
>
> I need to make a column of about 8000 values that simply alternates between one value and another, it needs to be 0 then 12 then 0 then 12... and so on.
>
> Can you help me out (pretty) please!
>
> THANKS!
>
> Dave

% Try something like this:
numValues = 8000;
firstValue = 0;
secondValue = 12;
A = repmat(firstValue,numValues,1);
A(2:2:end) = secondValue;

Subject: easy lil question (when you know how!)

From: Walter Roberson

Date: 6 Apr, 2009 21:15:32

Message: 5 of 10

Dave wrote:

> I need to make a column of about 8000 values that simply alternates between one value and another

TheMatrix = reshape(repmat([0 12], 8000/2, 1), [], 1);

Subject: easy lil question (when you know how!)

From: someone

Date: 6 Apr, 2009 21:24:01

Message: 6 of 10

TideMan <mulgor@gmail.com> wrote in message <c908ed77-88c6-4764-b0a4-5e02cb134a75@v23g2000pro.googlegroups.com>...
> On Apr 7, 8:47=A0am, "Dave " <yogi_c...@yahoo.com> wrote:
> > Hi!
> >
> > I need to make a column of about 8000 values that simply alternates betwe=
> en one value and another, it needs to be 0 then 12 then 0 then 12... and so=
> on.
> >
> > Can you help me out (pretty) please!
> >
> > THANKS!
> >
> > Dave
>
> y=3D[zeros(1,4000);12*ones(1,4000)];
> y=3Dy(:)

Iteresting solution!

I'll have to remember this one.

Subject: easy lil question (when you know how!)

From: Matt Fig

Date: 6 Apr, 2009 21:54:01

Message: 7 of 10

Without calling any functions:

G(1:8000,1) = 0;
G(2:2:end) = 12;

Subject: easy lil question (when you know how!)

From: someone

Date: 7 Apr, 2009 17:22:01

Message: 8 of 10

"Matt Fig" <spamanon@yahoo.com> wrote in message <grdtlp$2si$1@fred.mathworks.com>...
> Without calling any functions:
>
> G(1:8000,1) = 0;
> G(2:2:end) = 12;

% Technically, end is a function.
% But granted, you could just as easily have written:
G(2:2:8000) = 12;

Subject: easy lil question (when you know how!)

From: Matt Fig

Date: 7 Apr, 2009 17:40:17

Message: 9 of 10

"someone" <someone@somewhere.net> wrote in message
> % Technically, end is a function.
> % But granted, you could just as easily have written:
> G(2:2:8000) = 12;

I was wondering if someone (no pun intended) was going to call me on that!

Subject: easy lil question (when you know how!)

From: Dave

Date: 7 Apr, 2009 17:53:01

Message: 10 of 10

My goodness! there are a lot of solutions! Many many thanks to all of you.

Dave

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