Alternative to cell2mat

10 次查看(过去 30 天)
RDG
RDG 2011-12-4
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
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 个评论
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
[IX,IX]=sortrows(cell2mat(f));
newcell = f(IX);
No mat2cell() required.

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by