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:
Selectively Manipulate a Matrix

Subject: Selectively Manipulate a Matrix

From: anirbid.banerjee@gmail.com

Date: 25 Jan, 2009 01:56:54

Message: 1 of 5

Hi,

I am new to MATLAB, I have a matrix,

A = [0 1 2 4 5; 21 3 1 32 4; 55 23 2 1 1]

A =

     0 1 2 4 5
    21 3 1 32 4
    55 23 2 1 1

I have a subset of this matrix
S = [A(2,2:4); A(3,2:4)]

S=

     3 1 32
    23 2 1

I would like to assign all the corresponding elements in A to 0.
Precisely after the manipulation, I would like to get
A =
     0 1 2 4 5
    21 0 0 0 4
    55 0 0 0 1

Could somebody tell me a smarter matlab instruction/function that
could help me achieve this?

Regards,
Anirbid

Subject: Selectively Manipulate a Matrix

From: Roger Stafford

Date: 25 Jan, 2009 02:07:02

Message: 2 of 5

"anirbid.banerjee@gmail.com" <anirbid.banerjee@gmail.com> wrote in message <9cc7d144-6220-4039-8fc1-bd87d27a2166@t26g2000prh.googlegroups.com>...
> Hi,
>
> I am new to MATLAB, I have a matrix,
>
> A = [0 1 2 4 5; 21 3 1 32 4; 55 23 2 1 1]
>
> A =
>
> 0 1 2 4 5
> 21 3 1 32 4
> 55 23 2 1 1
>
> I have a subset of this matrix
> S = [A(2,2:4); A(3,2:4)]
>
> S=
>
> 3 1 32
> 23 2 1
>
> I would like to assign all the corresponding elements in A to 0.
> Precisely after the manipulation, I would like to get
> A =
> 0 1 2 4 5
> 21 0 0 0 4
> 55 0 0 0 1
>
> Could somebody tell me a smarter matlab instruction/function that
> could help me achieve this?
>
> Regards,
> Anirbid

 A(2:3,2:4) = 0;

Roger Stafford

Subject: Selectively Manipulate a Matrix

From: anirbid.banerjee@gmail.com

Date: 25 Jan, 2009 02:21:35

Message: 3 of 5

>
> =A0A(2:3,2:4) =3D 0;
>
> Roger Stafford

Thanks Roger, however I am not looking for this solution.
I have the subset of the matrix. This subset could have random
elements which you could not specify using 2:3, 2:4.

Anirbid

Subject: Selectively Manipulate a Matrix

From: Roger Stafford

Date: 25 Jan, 2009 03:07:02

Message: 4 of 5

"anirbid.banerjee@gmail.com" <anirbid.banerjee@gmail.com> wrote in message <aeccb990-d79e-4fbc-a977-dceab161bed2@r13g2000vbp.googlegroups.com>...
> >
> > A(2:3,2:4) = 0;
> >
> > Roger Stafford
>
> Thanks Roger, however I am not looking for this solution.
> I have the subset of the matrix. This subset could have random
> elements which you could not specify using 2:3, 2:4.
>
> Anirbid

  I think you would be wise to carefully describe the actual problem you are faced with, Anirbid. Give it in its most general form. Be sure to distinguish between the contents of array A and the locations therein. Give an example that demonstrates this generality. That's the way you can avoid the endless repetition that occurs so often in these newsgroup threads from misunderstandings.

Roger Stafford

Subject: Selectively Manipulate a Matrix

From: Matt Fig

Date: 25 Jan, 2009 03:12:02

Message: 5 of 5

> Thanks Roger, however I am not looking for this solution.
> I have the subset of the matrix. This subset could have random
> elements which you could not specify using 2:3, 2:4.
>
> Anirbid

The principle is the same, it is all just addressing. See the help for

ind2sub
sub2ind





X%gXf`vfvXDccXkvXbZkv^l\dfZevgm\P\fdY`v_Xf_l}kfvY1pe\<v_7}X

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