I want to read the header data. The data file is attached. In the fffffff row there are two data values that I need to read and also in the qqqqqq column there is only one data. How can i read this?
Mostrar comentarios más antiguos
The data file is attached. In the fffffff row there are two data values that I need to read and also in the qqqqqq column there is only one data. How can i read this? Please see the attached file.
4 comentarios
Mahdi
el 4 de Jun. de 2014
You didn't attach a file.
anton fernando
el 4 de Jun. de 2014
anton fernando
el 4 de Jun. de 2014
Image Analyst
el 5 de Jun. de 2014
You still didn't attach it. You attached a screenshot of it displayed in your screen. We need to see something with a .nc extension, not .jpg or other image format.
Respuesta aceptada
Más respuestas (2)
dpb
el 4 de Jun. de 2014
fid=fopen('yourfile','r');
fgetl(fid)
l=fgetl(fid);
datedata=sscanf(l(strfind(l,'|')+1:end),'%4d-2d-2d %2d:%2d:%2d+%2d');
fgetl(fid)
l=fgetl(fid);
data=sscanf(l(strfind(l,'|')+1:end),'%f');
Will have y,m,d,h,mn,s,tzoffset in datedata array and the floating pt value in data
Can do w/ textscan and 'headerline' but the fgetl call serves the purpose here.
3 comentarios
anton fernando
el 4 de Jun. de 2014
anton fernando
el 4 de Jun. de 2014
dpb
el 4 de Jun. de 2014
There is no column qqqqq?
The returned values for the header row are numeric; datedata are integer-valued while data isn't but they're all default doubles in Matlab.
If the question is to then read the tabular data, just skip a couple more lines and then since there's no formatting or skiping any text or the like, just a regular array, fscanf can return the full array in one swell foop.
As for what happens, read it from inside out after executing the first few lines at the command window to get a line into variable l. Look up strfind if you can't decipher what it's doing just from the name and arguments and
doc colon
doc end
for the addressing. The format strings are all described in the doc for fscanf and friends...there's no replacement for simply learning syntax and functionality in Matlab by reading the documentation and experimenting on the command line to see how something works.
anton fernando
el 4 de Jun. de 2014
Editada: anton fernando
el 4 de Jun. de 2014
0 votos
Categorías
Más información sobre Data Import and Export en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!