How can I use NaN padding instead of zero padding in a MATLAB array?

14 views (last 30 days)
When I run the following example, zero padding is applied to the nonspecified indices of the array. I would like to have NaNs instead of zeros for the nonspecified indices.
X(1,1) = 7;
X(2,2) = 3;
X
This returns the following:
X =
7 0
0 3
The desired result is:
X =
7 NaN
Nan 3

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 4 Dec 2009
The ability to use NaN padding with a single command is not available in MATLAB.
To work around this issue, you can replace all zeros with NaNs in your array using the following example:
X(1,1) = 7;
X(2,2) = 3;
X(X==0) = NaN;

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!