フィルターのクリア

textscan of csv files produces empty rows and cols

4 ビュー (過去 30 日間)
David C
David C 2012 年 6 月 21 日
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 件のコメント
David C
David C 2012 年 6 月 22 日
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 2012 年 6 月 22 日
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)), :) = [];

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by