Sort one Vector according to other Vector in octave
3 次查看(过去 30 天)
显示 更早的评论
Hi
Year_Month = [200705, 200708, 200710, 200707, 200712, 200711, 200706, 200709]
Year_Month_Name = ['May07';'Aug07';'Oct07';'July07';'Dec07';'Nov07';'June07';'Sept07']
How can I sort Year_Month_Name Vector as per Year_Month Vector. I tried this code but its not working. I am using octave version 4.2.2
[Year_Month,sortIdx] = sort(Year_Month,'ascend');
Year_Month_Name = Year_Month_Name(sortIdx);
Thank You
ajk
0 个评论
采纳的回答
Stephen23
2018-11-27
编辑:Stephen23
2018-11-27
If you use a character array and want to sort its rows, then you need to use the indexing on its rows:
Year_Month_Name = Year_Month_Name(sortIdx,:)
^^^^^^^ sort the *rows* of the matrix!
Basic subscript indexing is explained in the introductory tutorials:
As an alternative you could use a cell array and linear indexing.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Octave 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!