textscan of csv files produces empty rows and cols
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
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)), :) = [];
Respuestas (0)
Ver también
Categorías
Más información sobre Cell Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!