Reorganise table by label name
1 回表示 (過去 30 日間)
古いコメントを表示
Hi everyone,
I've multiple tables imported from excel where they are organized one for sheet. They include observation for countries at different times (sheet1=1-st year, sheet2 = 2-nd year,...). I'm trying to reorder them by their table labels (country name).
Can you help me? Thanks.
0 件のコメント
回答 (1 件)
Image Analyst
2020 年 4 月 12 日
Here is how to use sortrows() to reorder a table by the country names column:
% Sort table alphanumerically by the first column (the table with the country rows in it).
t = sortrows(t, 1)
Here is a full demo, which includes creating some data and then sorting it:
% No data was included in the question, so we are forced to create some on our own.
for row = 1 : 15
countries{row} = sprintf('Country %02d', randi(99, 1, 1));
data(row) = rand(1);
end
% Make a table from these two row vectors. Use (:) to turn them into column vectors, then use table().
t = table(countries(:), data(:), 'VariableNames', {'Country', 'Data'})
% Now we have the sample data with country names in random order, and we can begin.
% Sort table alphanumerically by the first column (the table with the country rows in it).
t = sortrows(t, 1)
3 件のコメント
Image Analyst
2020 年 4 月 12 日
Well, unless you can upload these multiple tables, or workbook with multiple sheets in it (ideally with code to read in all the sheets), you're making a lot harder for me. I think I'll just wait for the data, along with what you want as the output.
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!