Borrar filtros
Borrar filtros

How to read data as well as string headerlines?

1 visualización (últimos 30 días)
frewise
frewise el 1 de Dic. de 2011
Hi everyone, I have a file containing string and numbers like this
ID height weight score
a 160 80 66
b 165 85 80
c 170 90 67
d 168 61 95
when I tried to read it into matlab, I used
[id,h,w,s]=textread('file','%s %f %f %f','headerlines',1)
which gave 4 vectors and omitted the headerline. I want the headerline also to be read into a vector, anyone knows how to do this?
Thank you, best!

Respuesta aceptada

Amith Kamath
Amith Kamath el 1 de Dic. de 2011
a quickfix but dirty solution is to read everything as a string, as
[id,h,w,s]=textread('data','%s %s %s %s')
From the textread function reference at http://www.mathworks.com/help/techdoc/ref/textread.html, it is clear that including 'headerlines' in your parameter list ignores the headerline indicated by the number after it.
Using %s for everything stores the data all in cells, which you can convert to what you want later as need be!

Más respuestas (0)

Categorías

Más información sobre Text Data Preparation 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!

Translated by