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:
indexing and reordering issue

Subject: indexing and reordering issue

From: Mateusz Gos

Date: 20 Apr, 2010 11:28:04

Message: 1 of 3

The problem I am facing is as follows:
I have got a cell C = {'a' 'b' 'c'} and a vector V = [1 2 3], containing values that correspond to the names in cell (respectively). Now I get a new vector Vnew = [3 1] and want to somehow extract only the two corresponding elements from C, in the order they are in Vnem, so the result would be Cnew = {'c' 'a'}.

I have tried a couple of approaches, deploying cell, structures, string, but it seems to get me nowhere. Anyone can help?

cheers

Subject: indexing and reordering issue

From: Bruno Luong

Date: 20 Apr, 2010 11:35:07

Message: 2 of 3

[trash address] = ismember(Vnew, V)
Cnew = C(address)

% Bruno
 

Subject: indexing and reordering issue

From: us

Date: 20 Apr, 2010 11:40:06

Message: 3 of 3

"Mateusz Gos" <webmaster24@wp.pl> wrote in message <hqk344$l9d$1@fred.mathworks.com>...
> The problem I am facing is as follows:
> I have got a cell C = {'a' 'b' 'c'} and a vector V = [1 2 3], containing values that correspond to the names in cell (respectively). Now I get a new vector Vnew = [3 1] and want to somehow extract only the two corresponding elements from C, in the order they are in Vnem, so the result would be Cnew = {'c' 'a'}.
>
> I have tried a couple of approaches, deploying cell, structures, string, but it seems to get me nowhere. Anyone can help?
>
> cheers

well... how many approaches(?)...

one of the other solutions

     c={'a','b','c'};
     ix=[3,2];
     cn=c(ix)
% cn = 'c' 'b'

us

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