How to sort a table based off of values in one row in MATLAB

47 ビュー (過去 30 日間)
Allie Geiger
Allie Geiger 2021 年 3 月 8 日
コメント済み: Jan 2021 年 3 月 9 日
I am working on analyzing a data set for a 2AFC task. I have a table called 'SmallerTable,' that has multiple columns. One of my columns titled 'GroupB', I have various numbers ranging from 1:28 in this column. I would like to put these in order so that row one has the number 1, row two has the number 2 and so on. I would like every respective colum to sort their rows according to how this GroupB column is sorted.
Would anyone be able to help me with this?

回答 (2 件)

the cyclist
the cyclist 2021 年 3 月 8 日
編集済み: the cyclist 2021 年 3 月 8 日
Take a look at the documentation for the sortrows function, in particular the example on sorting rows of tables by variables. The syntax is basically
tblB = sortrows(tblA,vars)
where vars is a cell array with the variable name(s).
  2 件のコメント
Allie Geiger
Allie Geiger 2021 年 3 月 8 日
Thank you for your feedback I am getting the following error now:
Error using tabular/sortrows (line 88)
An error occurred when sorting the variable 'GroupB', whose type is 'table'.
Thank you for any and all help!
the cyclist
the cyclist 2021 年 3 月 8 日
Can you upload your data in a MAT file, using the paperclip icon in the toolbar?
If you cannot for some reason, could you upload a sample (perhaps just a few rows and columns) of the data that gives the same error?

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


Jan
Jan 2021 年 3 月 8 日
編集済み: Jan 2021 年 3 月 8 日
sortedTable = sortrows(SmallerTable, {'GroupB'})
  2 件のコメント
Allie Geiger
Allie Geiger 2021 年 3 月 8 日
Thank you for your feedback I am getting the following error now:
Error using tabular/sortrows (line 88)
An error occurred when sorting the variable 'GroupB', whose type is 'table'.
Thank you for any and all help!
Jan
Jan 2021 年 3 月 9 日
Then SmallerTable is not a table, because a column of a table cannot be a table also. Please post an example of your data.

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

カテゴリ

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