Borrar filtros
Borrar filtros

textscan of csv files produces empty rows and cols

4 visualizaciones (últimos 30 días)
David C
David C el 21 de Jun. de 2012
I have been using textscan to read large batches of CSV files, and every once in a while, I'd get a file that has "invisible" blank lines that get read into my data cellarray. Sometimes its blank rows, sometimes its blank columns, but they occur at end of the data only.
I'm trying to remove those blank rows and cols.
I'm using:
data(cellfun(@(X) isempty(X), data(:,1)), :) = [];
but its not working. I debugged it, and apparently matlab doesn't think those empty rows are empty.
Running isempty on one of those empty rows yeilds a value of 0, as wel as running on a row that DOES contain data
Anyone experience the same thing?
  4 comentarios
David C
David C el 22 de Jun. de 2012
the answers are the same if i test the cells that actually contain values too.
this problem goes away if I physically got into the CSV file with excel and delete those rows.
super strange
Walter Roberson
Walter Roberson el 22 de Jun. de 2012
Okay, and to double-check, you used
size round-bracket data curly-bracket K comma 1 curly-bracket round-bracket
?
If so then your cell array location is not empty because it contains a cell array (which might be empty)
Maybe,
data(cellfun(@(X) isempty(X) || (iscell(X) && all(cellfun(@(Y) isempty(Y),X)), data(:,1)), :) = [];

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Cell Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by