Why is importdata bringing in cell array?
조회 수: 18 (최근 30일)
이전 댓글 표시
I have two different .csv files that I would like to import and create structure arrays.
I'm using this:
A = importdata(filepath, filename);
The first one works and the heading looks like this:

The second one comes in as cell array so I cannot grab A.data:

What is the difference that I'm not seeing?
댓글 수: 3
dpb
2018년 11월 17일
What data, specifically are you wanting and how do you expect MATLAB to know where those data are or how they're organized for any totally arbitrary file excepting by some sort of preprocessing procedure?
detectImportOptions is the TMW-supplied routine to make a stab at that; anything else you do will be some variant of the techniques used therein.
채택된 답변
Mark Sherstan
2018년 11월 16일
You might have better luck going through the file line by line. For example:
f = fopen('test.csv');
lineCount = 1;
tline = fgetl(f);
while ischar(tline)
data{lineCount} = tline;
tline = fgetl(f);
lineCount = lineCount + 1;
end
fclose(f);
This will give you the header information as well but you can cut that out with a string compare assuming you know the header names or when the data becomes a number instead of a string. Just depends on how different all the .csv's might be.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Large Files and Big Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
