How to rearrange a cell array with a given index vector

72 ビュー (過去 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.
Sudhakar Shinde
Sudhakar Shinde 2020 年 10 月 22 日
yup.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by