sort arrays with sortrows

5 visualizaciones (últimos 30 días)
Pap
Pap el 1 de Mayo de 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 comentario
Jan
Jan el 1 de Mayo de 2011
What exactly is "th first column"? 'A', 'E', ... or 'ABC', 'ETE', ...?

Iniciar sesión para comentar.

Respuesta aceptada

Jarrod Rivituso
Jarrod Rivituso el 1 de Mayo de 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)
  1 comentario
Pap
Pap el 2 de Mayo de 2011
Many Many thanks Jarrod

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by