How to sort the output of variables of cell array ?

3 ビュー (過去 30 日間)
Ole
Ole 2017 年 8 月 8 日
編集済み: Stephen23 2017 年 8 月 8 日
I would like to sort the output of variables fx1 with the first digit and preserve the rows.
sortrows(data,1) does not work with cells
>> fx1{1}
ans =
5->2
fx1 =
'5->2'
'2->1'
'1->3'
'3->9'
'9->5'
'5->2'
'2->1'
Sorted to
'1->3'
'2->1'
'2->1'
'3->9'
'5->2'
'5->2'
'9->5'
sortrows(data,1) does not work with cells

採用された回答

Stephen23
Stephen23 2017 年 8 月 8 日
編集済み: Stephen23 2017 年 8 月 8 日
If it is a vector, why not simply use sort?:
>> sort(fx1)
ans =
'1->3'
'2->1'
'2->1'
'3->9'
'5->2'
'5->2'
'9->5'
If you want to sort by numeric value rather than character code then download my FEX submission natsortrows, which also includes natsort: one of these might do what you want.
  1 件のコメント
Ole
Ole 2017 年 8 月 8 日
Thanks I had an empty cell at the end and was giving error. Works fine with sort.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by