textscan of csv files produces empty rows and cols
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 22 Juin 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)), :) = [];
Réponses (0)
Voir également
Catégories
En savoir plus sur Cell Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!