Reading an Array in scientific notation from a txt
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ignacio
el 27 de Mayo de 2015
Comentada: Ignacio
el 27 de Mayo de 2015
Hi, I am trying to read the data from a txt file but I have been so far unable to manage to extract it using fscanf or textread.
the file is formatted as follows:
"Title1"
"Title2"
1.00000e-03 4.36579e-02
2.00000e-03 -8.85146e-02
3.00000e-03 -8.97553e-02
4.00000e-03 -7.65414e-02
5.00000e-03 -5.80485e-02
6.00000e-03 -4.28242e-02
7.00000e-03 -2.93374e-02
I am unable to read the numbers from the same line separately, and interpret them as numbers. Any help? Thanks!
1 comentario
Respuesta aceptada
dpb
el 27 de Mayo de 2015
d=textread('yourfile.dat','headerlines',2);
While textread has been deprecated to 'red-haired stepchild' status, it's very useful for some purposes such as this. Alternatively,
d=cell2mat(textscan(fid,'%f %f','collectoutput',1, ...
'headerlines',2));
textscan takes an additional fopen to get a valid file handle and then a cell2mat to cast to an ordinary array as it will return only a cell; hence the comment above that textread still has advantages/uses in some instances.
An explicit E or decimal will override the '%f' or you can use '%e' if you really, really want. You don't need to match any specific field width on input, the i/o scanning routines will deal with what they find as long as it's numeric and delimited field.
Más respuestas (0)
Ver también
Categorías
Más información sobre Text Files en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!