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:
re-indexing a cell array

Subject: re-indexing a cell array

From: mikimiko

Date: 27 Oct, 2010 08:24:49

Message: 1 of 4

Hello,
I have a cell array of the size 1X25 which I wish to re-arrange. That is, I would like create a new cell vector composed of the same data but now the cells are arranged in a different order which is determined by a certain vector - vector IX which has 25 IX ranging from 1-25.
Does anyone know how I do this with a cell array?
For a regular vector (A) I would just do A(IX) but that doesn't work for the cell array?

Subject: re-indexing a cell array

From: Steven_Lord

Date: 27 Oct, 2010 13:55:44

Message: 2 of 4



"mikimiko" <myartsev@weizmann.ac.il> wrote in message
news:1456762692.184204.1288167919832.JavaMail.root@gallium.mathforum.org...
> Hello,
> I have a cell array of the size 1X25 which I wish to re-arrange. That is,
> I would like create a new cell vector composed of the same data but now
> the cells are arranged in a different order which is determined by a
> certain vector - vector IX which has 25 IX ranging from 1-25.
> Does anyone know how I do this with a cell array?
> For a regular vector (A) I would just do A(IX) but that doesn't work for
> the cell array?

Have you tried it?

c = cell(1, 26);
for k = 1:26
    c{k} = char('a'-1+k);
end
rp = randperm(26);
c
c(rp)

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: re-indexing a cell array

From: Sean

Date: 27 Oct, 2010 14:00:06

Message: 3 of 4

mikimiko <myartsev@weizmann.ac.il> wrote in message <1456762692.184204.1288167919832.JavaMail.root@gallium.mathforum.org>...
> Hello,
> I have a cell array of the size 1X25 which I wish to re-arrange. That is, I would like create a new cell vector composed of the same data but now the cells are arranged in a different order which is determined by a certain vector - vector IX which has 25 IX ranging from 1-25.
> Does anyone know how I do this with a cell array?
> For a regular vector (A) I would just do A(IX) but that doesn't work for the cell array?

Like this:
%%%
A = num2cell(reshape(magic(5),[],1));
idx = randperm(25);
B = [A(idx)]

Subject: re-indexing a cell array

From: Jan Simon

Date: 28 Oct, 2010 16:18:05

Message: 4 of 4

Dear Sean,

> B = [A(idx)]
That's correct, but the square brackets are not needed. I think the OP was confused about the different braces and brackts at all, so I'd write this:
  B = A(idx)

Jan

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