MATLAB: Textscan – remove rows with special character

missingremovetextscan

I'm trying to read in a dataset, though it contains some rows with missing values which needs to be removed. The missing values are represented by a '?' in the dataset.
example of 3 rows:
1056784,3,1,1,1,2,1,2,1,1,2
1057013,8,4,5,1,2,?,7,3,1,4
1059552,1,1,1,1,2,1,3,1,1,2
Right now i'm doing this:
fid = fopen('bcw.data');
adata = textscan(fid,'%f%f%f%f%f%f%f%f%f%f%f','delimiter',',');
fclose(fid);
I need to remove the middle row (along with any other that contain a '?'), can anyone help with this? Thanks

Best Answer

Did you try the TreatAsEmpty option? When used, the value that will be substituted is controlled by the EmptyValue option, default NaN.
adatacell = textscan(fid,'%f%f%f%f%f%f%f%f%f%f%f','delimiter',',', 'TreatAsEmpty', '?', 'CollectOutput', 1);
adata = adatacell{1};
adata(any(isnan(adata),2),:) = []; %delete rows that have a NaN