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:
how to 'reindexing' an array

Subject: how to 'reindexing' an array

From: Hatoddyam Toto

Date: 4 Oct, 2012 14:28:16

Message: 1 of 2

Hi,
    I have an array A = [2 5 2 3 1 7 6 3 2 5]. It has 10 elements. I have another index set I=[9 5 4 1 2 7 6 8 10 3]. I want to assign I as index set of A, i.e. if I name the new array as newA, then newA(9)=2, newA(5)=5, ...,etc.

how can I do that?

thanks,
hato

Subject: how to 'reindexing' an array

From: dpb

Date: 4 Oct, 2012 15:16:49

Message: 2 of 2

On 10/4/2012 9:28 AM, Hatoddyam Toto wrote:
> I have an array A = [2 5 2 3 1 7 6 3 2 5]. It has 10 elements. I
> have another index set I=[9 5 4 1 2 7 6 8 10 3]. I want to assign I
> as index set of A, i.e. if I name the new array as newA, then
> newA(9)=2, newA(5)=5, ...,etc.
...

Did you simply try the obvious???

B(I)=A;

Hint--as a way sometimes to see, try writing the explicit loop and
vectorize...

The most straightahead direct translation would be

for i=1:10,B(I(i))=A(i);end

Now work out the non-loop steps...

B(I(1:10))=A(1:10);

The next should be obvious if the above wasn't...

--


--

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