Azzera filtri
Azzera filtri

sort arrays with sortrows

1 visualizzazione (ultimi 30 giorni)
Pap
Pap il 1 Mag 2011
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 Commento
Jan
Jan il 1 Mag 2011
What exactly is "th first column"? 'A', 'E', ... or 'ABC', 'ETE', ...?

Accedi per commentare.

Risposta accettata

Jarrod Rivituso
Jarrod Rivituso il 1 Mag 2011
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)

Più risposte (0)

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by