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:
Sequence of numbers

Subject: Sequence of numbers

From: Ulrik Nash

Date: 29 Oct, 2013 00:03:06

Message: 1 of 2

This is an example of the result I wish to achieve:

[2 2 2 3 3 3 4 4 4]

More generally, I wish to create a vector starting at min and finishing at max, displaying n numbers of each value, with increments, inc, of 1.

In the above example, min = 2, max = 4, n = 3, and inc = 1.

Can this be done without looping?

Subject: Sequence of numbers

From: Gene

Date: 29 Oct, 2013 14:22:07

Message: 2 of 2

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <l4mtvq$18s$1@newscl01ah.mathworks.com>...
> This is an example of the result I wish to achieve:
>
> [2 2 2 3 3 3 4 4 4]
>
> More generally, I wish to create a vector starting at min and finishing at max, displaying n numbers of each value, with increments, inc, of 1.
>
> In the above example, min = 2, max = 4, n = 3, and inc = 1.
>
> Can this be done without looping?

Hi Ulrich

A =reshape(repmat([v_min:v_inc:v_max], n, 1), 1, n*length([v_min:v_inc:v_max]))

Avoid using min,max for variable names

gene

Tags for this Thread

No tags are associated with 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