Got Questions? Get Answers.
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:
How to create multiple vectors with a loop

Subject: How to create multiple vectors with a loop

From: Simone Lenzu

Date: 27 Oct, 2010 17:37:04

Message: 1 of 2

Hi, I would like MATLAB to create n different vecotors indexed by a number.
I would like something like this

N=5
for i=1:N
 x(i)=rand(3)
end

I know this is probably a pretty trivial task, but I can't find a way to say this to MATLAB.
Thank you

S

Subject: How to create multiple vectors with a loop

From: Sean

Date: 27 Oct, 2010 17:45:10

Message: 2 of 2

"Simone Lenzu" <simonelenzu100586@gmail.com> wrote in message <ia9o00$646$1@fred.mathworks.com>...
> Hi, I would like MATLAB to create n different vecotors indexed by a number.
> I would like something like this
>
> N=5
> for i=1:N
> x(i)=rand(3)
> end
>
> I know this is probably a pretty trivial task, but I can't find a way to say this to MATLAB.
> Thank you
>
> S

You'll have to use cells to do exactly what you want:
%%%
x = cell(N,1);
for ii = 1:N
   x{ii} = rand(3);
end

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