Why is importdata bringing in cell array?

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:
1.JPG
The second one comes in as cell array so I cannot grab A.data:
2.JPG
What is the difference that I'm not seeing?

3 comentarios

dpb
dpb el 16 de Nov. de 2018
Not possible to tell for certain w/o actual files nor is it clear what the definition of "works" is...and, of course you can dereference a cell array to retrieve whatever it is that is wanted from it... :)
With a (largeish) assumption about the above, what appears different visually is there's a blank row after the header rows before the numeric data in the first but not in the second--that may be sufficient of a clue to importdata without additional help to be able to find the array in the former that doesn't succeed in the latter--but that's a guess.
You might, instead, try using detectImportOptions first and then readtable for both; it quite possibly may take some intervention regarding knowledge of the file format to be totally successful; expecting magic to occur is, on occasion, not yielded in results...
K
K el 16 de Nov. de 2018
Thanks for the response!
By "works" I mean just having the ability to grab an array of all data points in the data file. The second file comes in as a cell array that is made up of only one column
3.JPG
I'm just trying to get a program that grabs that data no matter how many header lines there are. I definitely might be able to get it using readtable but it will be inefficient if I use this in the code.
dpb
dpb el 17 de Nov. de 2018
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.

Iniciar sesión para comentar.

 Respuesta aceptada

Mark Sherstan
Mark Sherstan el 16 de Nov. de 2018
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.

Más respuestas (0)

Categorías

Más información sobre Large Files and Big Data en Centro de ayuda y File Exchange.

Productos

Versión

R2016b

Etiquetas

Preguntada:

K
K
el 16 de Nov. de 2018

Comentada:

dpb
el 17 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by