필터 지우기
필터 지우기

Problem with dlmread reading data

조회 수: 2 (최근 30일)
Jonathan Gundorph Jansen
Jonathan Gundorph Jansen 2018년 3월 1일
답변: Star Strider 2018년 3월 1일
Dear Mathworks community,
I am having a problem using the dlmread function. I want to read data from a GNU zipped file (gravitational data from the GRACE satellite) into MATLAB so I can work with it. This is my approach so far:
MyFolderInfo = dir('C:\Users\my\Desktop\Skole\6. Semester\Bachelor_Projekt\GRACE')
listing = MyFolderInfo(4).name
M = dlmread(listing,' ', [8, 0, 5150, 9])
So I am succesfully loading the data from dir, but when I want to use the dlmread function I get the following error:
*Error using dlmread (line 147)
Mismatch between file and format character vector.
Trouble reading 'Numeric' field from file (row number 1, field number 1) ==> GRCOF2 0 0 0.883194575888E-11
0.000000000000E+00 0.0000E+00 0.0000E+00 20020405.0000 20020501.0000 nnnn \n*
I want to use only the numerical data and exclude the columns "GRCOF2" and "nnnn", but when I try to make the row and column offset, like below, i just get the following error.
M = dlmread(listing,' ', [8, 1, 5150, 8])
Trouble reading 'Numeric' field from file (row number 1, field number 16) ==> nnnn \n
Its almost as it doesn't register my max. column offset correctly. Can anyone help me?
Best Regards Jonathan
PS. I've attached an image of data file that I want to work with in this question, if that helps. It's opened in notepad++.

채택된 답변

Star Strider
Star Strider 2018년 3월 1일
Your file is not appropriate for dlmread. Use textscan (link) instead.
This should get you started:
fidi = fopen(MyFolderInfo(4).name, 'rt');
Data = textscan(fidi, '%s%f%f%f%f%f%f%f%f%s', 'HeaderLines',8, 'CollectOutput',1);
You may have to experiment with the name-value pairs in textscan to work with your file. See the documentation for all the possibilities.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by