Is there an efficient method to sort rows of a table, based on a particular column, in a particular order, that is not either 'ascend' or 'descend'
7 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I believe this is probably an incredibly easy thing to do but it doesn't seem to be possible with sortrows function, based on the documentation.
I have a database, existing as a table variable, with about 20 columns of various data classes. Is there a way to sort the table using a specific order of a column? For example, if I have a table specified as the following:
opts = ["optionA";"optionB";"optionC"];
vals = [1 10 100];
table(opts,vals)
Is there a way to sort specifically by an externally defined order, perhaps by a new variable, such as:
order = ["optionB","optionA","optionC"]
I know that I could do this with forloops or something of that nature, but I find it hard to believe this capability doesnt already exist, and I think I am just skipping over something in the documentation. In addition to answering the question, can you please also provide the link to the documentation that shows me where I missed this in the first place?
Thanks!
0 件のコメント
回答 (1 件)
Image Analyst
2019 年 2 月 3 日
If you have some vector that gives the order you want the vector arranged in, just use that as an index. Example:
sortedVector = vec(sortOrder);
where sortOrder is the order you want them sorted in and vec is your original vector.
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!