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:
Problem with filling out the array in the vectorised way

Subject: Problem with filling out the array in the vectorised way

From: Liana

Date: 20 Apr, 2011 06:29:06

Message: 1 of 3

Hello,

I have the following question. I need to fill specific cells of an array. So, I have indices of rows and columns, defined as follows:
a = [2; 2; 3]; % indices of rows
b = [1; 2; 3]; % indices of columns

Each pair ab corresponds to specific cell of the array.

And there is the array A:
A = zeros(3)
A =
     0 0 0
     0 0 0
     0 0 0

By running A(a,b) = 1, I've excepted to get:
A =
     0 0 0
     1 1 0 (2x1, 2x2)
     0 0 1 (3x3)

However, I received:
A =
     0 0 0
     1 1 1
     1 1 1

How can I fill this array in the way I've been expected? Thank you.

Subject: Problem with filling out the array in the vectorised way

From: Matt J

Date: 20 Apr, 2011 10:39:04

Message: 2 of 3

"Liana" wrote in message <iolufi$h8l$1@fred.mathworks.com>...
>
> By running A(a,b) = 1, I've excepted to get:
> A =
> 0 0 0
> 1 1 0 (2x1, 2x2)
> 0 0 1 (3x3)
>
> However, I received:
> A =
> 0 0 0
> 1 1 1
> 1 1 1
>
> How can I fill this array in the way I've been expected? Thank you.
======================


I assume you found the necessary answers in this thread?

http://www.mathworks.com/matlabcentral/newsreader/view_thread/306489

Subject: Problem with filling out the array in the vectorised way

From: Liana

Date: 21 Apr, 2011 02:24:04

Message: 3 of 3

The problem is solved.

"Matt J" wrote in message <iomd48$d1i$1@fred.mathworks.com>...
> "Liana" wrote in message <iolufi$h8l$1@fred.mathworks.com>...
> >
> > By running A(a,b) = 1, I've excepted to get:
> > A =
> > 0 0 0
> > 1 1 0 (2x1, 2x2)
> > 0 0 1 (3x3)
> >
> > However, I received:
> > A =
> > 0 0 0
> > 1 1 1
> > 1 1 1
> >
> > How can I fill this array in the way I've been expected? Thank you.
> ======================
>
>
> I assume you found the necessary answers in this thread?
>
> http://www.mathworks.com/matlabcentral/newsreader/view_thread/306489

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