how to sort data

16 ビュー (過去 30 日間)
Pat
Pat 2011 年 9 月 15 日
コメント済み: Jamie Smith 2015 年 10 月 17 日
I have two column of datas
COLUMN1 COLUMN2
5 R
3 E
1 A
4 P
i NEED THE OUTPUT AS
1 A
3 E
4 P
5 R
CAN ANYONE TELL HOW TO PROCESS PLEASE
  3 件のコメント
Jan
Jan 2011 年 9 月 15 日
@Pat: If I'm looking on your other 30 questions, it seems, like you are not interested in answering questions for clarifications. Answering your questions would be much easier, if you take the time to explain all necessary details. Almost the half of your question do not get any answer, and you could accept two answers only. I recommended the standard usage of upper/lower-case characters before, but without impressing you.
If you do not use this forum for an efficient exchange of information, why do you use it at all?
Jan
Jan 2011 年 9 月 15 日
@Pat: Now the format is much nicer to read.

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

採用された回答

Jan
Jan 2011 年 9 月 15 日
If "COLUMN1 COLUMN2 5 R 3 E 1 A 4 P" means this:
data = {5, 'R'; ...
3, 'E'; ...
1, 'A'; ...
4, 'P'};
Then you can sort it this way:
[dummy, index] = sort([data{:, 1}]);
sorted = data(index, :);
  1 件のコメント
Jamie Smith
Jamie Smith 2015 年 10 月 17 日
how can this be done for much larger excel file that contains words in the first column? I need to arrange the table so that the values in the 8th column are in ascending order but in doing so keep their respective names in the first column?

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

その他の回答 (1 件)

Andrei Bobrov
Andrei Bobrov 2011 年 9 月 15 日
data = reshape({5 'R' 3 'E' 1 'A' 4 'P'},2,[])'
out = sortrows(data,1)
or
out = reshape(sortrows(data,1)',1,[])
if
data(:,1)=cellfun(@num2str,data(:,1),'un',0)
out = sortrows(data,1)
  3 件のコメント
Pat
Pat 2011 年 9 月 15 日
thank you sir can u please can u tell how to do it in descending order please
Andrei Bobrov
Andrei Bobrov 2011 年 9 月 15 日
out = sortrows(data,-1)

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

カテゴリ

Help Center および File ExchangeVariables についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by