From: Oleg Komarov on
"Antonio Trujillo-Ortiz" <atrujo(a)uabc.edu.mx> wrote in message <i0hbsv$ker$1(a)fred.mathworks.com>...
> Hi Joerg,
>
> Thanks for your answer. I'm sorry. In my initial post in the resulting matrix R, I miss to type the 3rd row. So, it must be:
>
> R=[6 0 3;7 2 6;5 1 2;6 1 5];
>
> As you can see. In the initial matrix A with NaN's,
>
> A = [NaN 0 3;7 2 6;5 1 2;NaN NaN 5];
>
> I have the columns 1 & 2 with them. With the two corresponding nanmeans=6,1. Which I need to replace with its corresponding NaN's elements.
>
> I'm awaiting for any hint.
>
> Thx.


A = [NaN 0 3;7 2 6;5 1 2;NaN NaN 5];

% column nanmeans (I suppose you have the Stats TB)
colMeans = nanmean(A);
% Find the position of nans
[row,col] = find(isnan(A));
% Replace with means
A(isnan(A)) = colMeans(col);

Oleg