function A = fill_nans(A)% Replaces the NaN in each column with
% previous non-NaN values.
for i = 1:size(A,1) I = A(1,i) for j = 2:size(A,2) if cellfun(@isnan,A(i,j)) A(i,j) = I else I = A(i,j) end endendI use this function data={'Robert',NaN,5,6,7,8,NaN,NaN,NaN};fill_nans(data) %working ok
data2={'Robert','pai',NaN,5,6,7,8,NaN,NaN,NaN};fill_nans(data2) %Not working error is
data3={'Robert',NaN,NaN,5,6,7,8,'pai',NaN,NaN,NaN};fill_nans(data2) %Not working error is
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
Error in fill_nans (line 8)
if cellfun(@isnan,A(i,j))
Best Answer