Alternative to cell2mat

I have a cell array, f with contents in it.
Is there a way to sort the contents of the cell array using
[B,IX]=sort(f) without having to use cell2mat?
I would like to evaluate it directly.

1 件のコメント

Walter Roberson
Walter Roberson 2011 年 12 月 4 日
Hmmm... what kind of contents? It is, for example, difficult to sort 'hello' against [18.2 13.39 9.44]

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

回答 (2 件)

Fangjun Jiang
Fangjun Jiang 2011 年 12 月 4 日

1 投票

If f is a cell array of strings, you can run sort(f) directly. If you f contains numerical data, what do you try to sort of the size of data is different. You need to provide more details. And what is wrong with using cell2mat()? What is the rational for "evaluate it directly"?

5 件のコメント

RDG
RDG 2011 年 12 月 4 日
The data type in each cell array is a 10x4 double. I'll be looping an evaluation. If I were to use cell2mat(), after the evaluation, I've to use mat2cell() again for the evaluation to continue...and at times it causes issue.
That's why I'm trying to evaluate the cell array as it is. without using cell2mat() function.
RDG
RDG 2011 年 12 月 4 日
Sorry. I meant the data type is a 10x1 cell with number in its content.
80
80
70
90
80
70
50
60
70
140
Fangjun Jiang
Fangjun Jiang 2011 年 12 月 4 日
C={8,7,9}
[d,ind]=sort(cell2mat(c))
C=c(ind)
Fangjun Jiang
Fangjun Jiang 2011 年 12 月 4 日
Should be all low-case 'c'. Smart phone is too smart.
Jan
Jan 2011 年 12 月 4 日
In this case [C{:}] is faster than CELL2MAT.

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

Walter Roberson
Walter Roberson 2011 年 12 月 4 日

0 投票

[IX,IX]=sortrows(cell2mat(f));
newcell = f(IX);
No mat2cell() required.

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

タグ

質問済み:

RDG
2011 年 12 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by