フィルターのクリア

Gradient and NaN

25 ビュー (過去 30 日間)
Camil Hamel
Camil Hamel 2011 年 1 月 24 日
What does the function gradient does with nan?

回答 (2 件)

Matt Fig
Matt Fig 2011 年 1 月 24 日
You can see what MATLAB does by looking at a plot. Look at the difference between the two figures:
v = -2:0.5:2;
[x,y] = meshgrid(v);
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.5,.5);
quiver(v,v,px,py),
z(5,5) = nan; % Set the central data to nan.
[px2,py2] = gradient(z,.2,.2);
figure
quiver(v,v,px2,py2)

Walter Roberson
Walter Roberson 2011 年 1 月 25 日
>> [fx,fy] = gradient([1 nan 3;5 9 15])
fx =
NaN 1 NaN
4 5 6
fy =
4 NaN 12
4 NaN 12
In other words, any location whose value would involve using the nan in the calculation, gets calculated as nan. Which is the result you would expect if the routine did simple arithmetic operations without any checking for nan.

カテゴリ

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