I have arrays like this:
[1 NaN NaN]
[NaN 2 NaN]
[NaN NaN 3]
How can I merge them to
[1 2 3]
?
I have arrays like this:
[1 NaN NaN]
[NaN 2 NaN]
[NaN NaN 3]
How can I merge them to
[1 2 3]
?
Concatenate the vectors into a matrix and then compute the mean of each column discarding NaN's:
vectors = {[1 NaN NaN], [NaN 2 NaN], [NaN NaN 3]};
result = mean(vertcat(vectors{:}), 1, 'omitnan'); % or nanmean(vertcat(vectors{:}),1)
vectors = [[1 NaN NaN]; [NaN 2 NaN]; [NaN NaN 3]]; result = mean(vectors,'omitnan')You can combine all your matrices like so (this puts A on top of B):
C = [A ; B];
Then you can detect the cells that are not NaN:
D = ~isnan(C);
After that you can select with those logicals:
e = C(D);
This is now a vertical vector, you can make it horizontal with:
e = e';