Borrar filtros
Borrar filtros

Select/ Short rows from ASCII files

1 visualización (últimos 30 días)
Pap
Pap el 14 de Sept. de 2011
Hello,
I work with very large ASCII file, as the below sample
STOCK DATE TIME PRICE
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
which is TAB delimited and sorted by TIME as above.
How can I select rows with respect to the column 'STOCK'
for instance selecting only the rows for the stock 'ABC' ?
In case these are not then sorted by time, how can I sort them by TIME?
Many thanks in advance.
Panos

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 14 de Sept. de 2011
Import your ASCII file first. If you could make the data like the format below, it's straightforward to use ismember() and sort() function to achieve what you want.
Data={'ETE' '04/10/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';
'ABC' '04/02/2010 10190000' 18.54 300 'Big Cap';}
Ind=ismember(Data(:,1),'ABC')
Stock_ABC=Data(Ind,:)
[Trash,Ind]=sort(datenum(Data(:,2),'mm/dd/yyyy HHMMSSFFF'));
Stock_Sorted=Data(Ind,:)
  2 comentarios
Pap
Pap el 14 de Sept. de 2011
The thing is that it is a very large ASCII file. (almost 9,000,000 rows) so I cant make the data as the format above
Thanks
Panos
Fangjun Jiang
Fangjun Jiang el 14 de Sept. de 2011
I don't mean to manually type into that format. You can use uiimport(),importdata(), xlsread() or textscan() to import your ASCII file and then make your data into a cell array.

Iniciar sesión para comentar.

Más respuestas (1)

Pap
Pap el 14 de Sept. de 2011
Thanks so much Fangjun!
Is there any way to export the result in a new ASCII file?
Panos
  1 comentario
Fangjun Jiang
Fangjun Jiang el 14 de Sept. de 2011
Yes. xlswrite() can write a cell array to an Excel file which I think would be better for this type of information. You can also use csvwrite(), dlmwrite() to write to an ASCII text file.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by