Clear Filters
Clear Filters

How can I center a matrix containing NaN values?

2 views (last 30 days)
I have a matrix of size 72x144. It contains many NaN values, but also contains numeric values. I have been successful in the past at centering matrices containing only numeric values using the following code:
xctr=bsxfun(@minus, x, sum(x)/size(x, 1));
However, this seems to output a matrix with all NaN values, rather than giving me many NaN values, and also the centered numerical values. How can I center the data without turning everything into NaN?
Image Analyst
Image Analyst on 30 Oct 2013
What does it mean to "center" a matrix with nan's sprinkled throughout it? Can you give a small example of the input matrix and desired output matrix?
Patrick on 30 Oct 2013
X = [ NaN NaN NaN | 6 4 2 | NaN 4 NaN ]
xctr = [ NaN NaN NaN | 2 0 -2 | NaN 0 NaN ]

Sign in to comment.

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 30 Oct 2013
if you statistic toolbox
xctr=bsxfun(@minus, x, nansum(x)/size(x, 1));

More Answers (0)


Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!