sort arrays with sortrows

5 ビュー (過去 30 日間)
Pap
Pap 2011 年 5 月 1 日
Hello,
%I have the below txt file.
Stock Date Time Price Volume Stock Category
ETE 04/01/2010 10145959 18.31 500 Big Cap
ETE 04/01/2010 10150000 18.01 70 Big Cap
ETE 04/01/2010 10170000 18.54 430 Big Cap
ABC 04/01/2010 10190000 18.34 200 Big Cap
YYY 04/01/2010 10200000 18.34 100 Big Cap
% How can I sort this rows with respect the first column (alphabetically or not) using sortrows ( or something else), so the file will look like:
ABC 04/01/2010 10190000 18.34 200 Big Cap
ETE 04/01/2010 10145959 18.31 500 Big Cap
ETE 04/01/2010 10150000 18.01 70 Big Cap
ETE 04/01/2010 10170000 18.54 430 Big Cap
YYY 04/01/2010 10200000 18.34 100 Big Cap
Any hint?
Many thanks in advance
Panos
  1 件のコメント
Jan
Jan 2011 年 5 月 1 日
What exactly is "th first column"? 'A', 'E', ... or 'ABC', 'ETE', ...?

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

採用された回答

Jarrod Rivituso
Jarrod Rivituso 2011 年 5 月 1 日
How are you reading the data into MATLAB? I think the format you have the data stored in could make or break sortrows in certain cases.
Here's a method where sortrows would work...
%Open file
fid = fopen('myFile.txt');
%Read data in as 1-by-7 cell array of each column
data = textscan(fid,'%s%s%s%s%s%s%s')
%Convert data to 5-by-7 cell array of each data element
data2 = [data{:}]
%Sort data based on first row. Characters can be treated as numeric, so this works
dataSorted = sortrows(data2,1)
  1 件のコメント
Pap
Pap 2011 年 5 月 2 日
Many Many thanks Jarrod

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

その他の回答 (0 件)

カテゴリ

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