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

14 ビュー (過去 30 日間)
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

採用された回答

MathWorks Support Team
MathWorks Support Team 2009 年 12 月 4 日
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;

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by