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:
Selecting values in matrix based on index

Subject: Selecting values in matrix based on index

From: Ulrik Nash

Date: 12 Jul, 2010 11:47:05

Message: 1 of 2

Hi Everyone,

I thought I had this one nailed, but I can't seem to get what i want:

Suppose I have a matrix A:

A = [1 5; 2 3; 4 4]

and B

B = [1 3]

Now, I want to select the values in A given by the index in B, but in column 2, not column 1

If I use the command:

C = A(B)

I get the correct rows, but not the correct column.

What am I missing?

Kind regards,

Ulrik.

 

Subject: Selecting values in matrix based on index

From: Ulrik Nash

Date: 12 Jul, 2010 12:04:05

Message: 2 of 2

"Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <i1evbp$lmv$1@fred.mathworks.com>...
> Hi Everyone,
>
> I thought I had this one nailed, but I can't seem to get what i want:
>
> Suppose I have a matrix A:
>
> A = [1 5; 2 3; 4 4]
>
> and B
>
> B = [1 3]
>
> Now, I want to select the values in A given by the index in B, but in column 2, not column 1
>
> If I use the command:
>
> C = A(B)
>
> I get the correct rows, but not the correct column.
>
> What am I missing?
>
> Kind regards,
>
> Ulrik.
>
Sorry, to waste time. I got it:

C = A(B,2)

Correct me if I am wrong...

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