如何按浮点列对 Octave 中的元胞数组进行排序?
我在 Octave 中创建了一个元胞数组。有些列包含浮点数,有些列包含字符串。我可以使用以下命令按字符串列(例如第4列)对元胞数组进行排序:
sortrows (mycellarray, 4);
但是如果我要排序的列是浮点数列em>,然后我收到此错误消息:
error: sort: only cell arrays of character strings may be sorted
有谁知道如何按浮点列对元胞数组进行排序?
I created a cell array in Octave. Some columns contain floats, and some columns contain strings. I am able to sort the cell array by a column of strings (say col #4), using this command:
sortrows (mycellarray, 4);
But if the column I want to sort by is a column of floats, then I get this error message:
error: sort: only cell arrays of character strings may be sorted
Does anyone know how to sort a cell array, by a column of floats?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将具有浮点值的列转换为向量,对其进行排序并获取排序索引。然后您可以将此索引应用于元胞数组。
然而,在 Octave 的某些版本中,未定义波形符
~
运算符。在这种情况下:Convert the column with float values to a vector, sort it and get the sorting index. Then you can apply this index to your cell array.
In some versions of Octave, however, the tilde
~
operator is not defined. In that case: