matlab - Removing rows by indexing -
i have cell array of approx 300 rows. array has 6 columns. in 6th column lots of rows zeros. want remove these rows array.
i using line below getting error message saying "undefined function 'ne' input arguments of type 'cell'."
mydata = mydata(mydata(:,6) ~= 0);
if it's cell array of numerals, try -
mydata(~vertcat(mydata{:,6}),6)={[]}
or
mydata(~cell2mat(mydata(:,6)),6)={[]}
or this, purely @chappjc's comments
mydata(~[mydata{:,6}],6)={[]}
if it's cell array of characters, try -
mydata(~str2double(mydata(:,6)),6)={''}
edit 1: if remove entire rows if corresponding elements in 6th column zeros, index whole row using :
. thus, above codes change following forms respectively :
mydata(~vertcat(mydata{:,6}),:)={[]} mydata(~cell2mat(mydata(:,6)),:)={[]} mydata(~[mydata{:,6}],:)={[]} mydata(~str2double(mydata(:,6)),:)={''}
edit 2: if remove rows cell array have empty cells, may use -
mydata(all(cellfun('isempty', mydata),2),:) = []
Comments
Post a Comment