MATLAB: Delete the row where is a NaN

arraysmatrix

Dear all,
I am stuck in a silly programming problem and I would like to ask for some help please.
I have two cells a and b:
a=num2cell(1:10); b=num2cell(1:10);
in each cell, I have 10 column vectors (n x 1). The cell "a" has a NaN that I would like to delete. I also would like to multiply the matrices in each cell. However if I delete some row in a{i} then the matrix size will change so I have to delete the same row in b{i} so that the matrices a{i} and b{i} have the same size. To illustrate what I am trying to achieve, here the structure of my code:
for i=1:10
if a{i}(isnan(a{i}))
%% complete here
end
a{i}'*b{i};
end
I would greatly appreciate if you could help me complete the code. Basically I would like to tell the code "if there is a NaN in a{i}, please delete the row, and show me the row number. Then I will delete the same row in b{i} and finally multiply a{i} and b{i}.
Thanks a lot
Kind Regards
S

Best Answer

Looping will be faster than proposals based on cellfun or arrayfun
for i=1:10
badrows=any(isnan(a{i}),2);
a{i}(badrows,:)=[];
b{i}(badrows,:)=[];
a{i}'*b{i};
end