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:
Matrix

Subject: Matrix

From: Pradeep Ramalingam

Date: 25 May, 2010 07:06:04

Message: 1 of 3

i'm creating a matrix 10*10 in which 50% of them needs to be filled with number 3 and remaining 50% can be filled in random from 0 to 2... please help... need some assistance...

Subject: Matrix

From: Darren Rowland

Date: 25 May, 2010 07:36:06

Message: 2 of 3

A = floor(3*rand(10));
r = randperm(100);
A(r(1:50)) = 3;

Hth
Darren

Subject: Matrix

From: Roger Stafford

Date: 25 May, 2010 07:38:05

Message: 3 of 3

"Pradeep Ramalingam" <pradeep.ramalingam@gmail.com> wrote in message <htfsss$13i$1@fred.mathworks.com>...
> i'm creating a matrix 10*10 in which 50% of them needs to be filled with number 3 and remaining 50% can be filled in random from 0 to 2... please help... need some assistance...
- - - - - - - - -
 m = 3*ones(10);
 p = randperm(100);
 m(p(1:50)) = floor(3*rand(50,1));

I am assuming here you intended the replacements to be integers 0, 1, and 2. Otherwise replace the floor(3*rand(50,1)) with 2*rand(50,1).

Roger Stafford

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