How to rearrange a cell array with a given index vector

조회 수: 77 (최근 30일)
Ranitha Mataraarachchi
Ranitha Mataraarachchi 2020년 10월 22일
댓글: Sudhakar Shinde 2020년 10월 22일
I have the following cell array as matrices for its content. Matrices are of variable dimension.
c{1} = [1,2,3];
c{2} = [2,3,5,6];
c{3} = [1,2];
What is requires is to sort the given cell array 'c' according to a index vector.
if index vector is idx,
idx = [2;3;1];
I want the cell array 'c' to look like
c{1} = [2,3,5,6];
c{2} = [1,2];
c{3} = [1,2,3];
I tried using the command
c = c(idx);
which should work if c were a numerical array, but the command returns in an error. How do I get about this?
Thank you.
  댓글 수: 1
madhan ravi
madhan ravi 2020년 10월 22일
What was the error message? It works without any problem.

댓글을 달려면 로그인하십시오.

채택된 답변

Sudhakar Shinde
Sudhakar Shinde 2020년 10월 22일
편집: Sudhakar Shinde 2020년 10월 22일
change semicolon to comma to seperate 2 & 3 from id:
idx = [2,3,1];
  댓글 수: 5
madhan ravi
madhan ravi 2020년 10월 22일
Semi colon or comma both works.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by