textscan of csv files produces empty rows and cols
4 views (last 30 days)
Show older comments
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 Comments
Walter Roberson
on 22 Jun 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)), :) = [];
Answers (0)
See Also
Categories
Find more on Cell Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!