imagesc 将 NaN 值显示为非 NaN
imagesc showing NaN values as not NaN
下图中的红色补丁显示了数值模型的域。绿色补丁显示地球。
我想为模型域中的点创建一个矩阵,其中包含地球表面以上的高度值。
我使用以下代码:
close all
clear all
%%%slope coefficient
a=1/50;
%%%resolution
dx = 500;
dz = 2.5;
%%%define domain
xi = 0:dx:200e3;
zi = 0:dz:6e2;
m=length(zi);%domain dimension
n=length(xi);%domain dimension
%%%max z where the slope starts
zs = find(zi==max(zi));
for ii=1:n %for every x
zslope = -a*xi(ii)+zi(zs);%equation of the slope
zz(ii)=zslope;
if zslope>=0 %if the slope is still in the domain (z>0)
for jj=1:m %for every z
if zi(jj)>=zslope %above the slope
Z(jj,ii) = zi(jj)-zslope; %height above the slope
elseif zi(jj)<zslope %below the slope (ground)
Z(jj,ii)=NaN;
end
end%for on z
elseif zslope<0 %the slope is no longer in the domain
for jj=1:m %for every z
Z(jj,ii) = zi(jj)-zslope; %height above the slope
end
end
end%for on x
这似乎工作正常:
figure;
imagesc(Z)
colorbar
事实上,点 240 的值正如人们所期望的那样是 600。
问题
问题是在工作区中 Z
矩阵充满了 NaN
s!
当值是 NaN
时,imagesc
如何不显示 NaN
值?
注意
如果我评论这些行
elseif zi(jj)<zslope %below the slope (ground)
Z(jj,ii)=NaN;
没问题。
NaN
显示为颜色条中的最低值(反之亦然)。如果要从图中删除 NaN 值,可以使用 isnan
和 AlphaData
属性.
imagesc(Z,'AlphaData',~isnan(Z))
下图中的红色补丁显示了数值模型的域。绿色补丁显示地球。
我想为模型域中的点创建一个矩阵,其中包含地球表面以上的高度值。
我使用以下代码:
close all
clear all
%%%slope coefficient
a=1/50;
%%%resolution
dx = 500;
dz = 2.5;
%%%define domain
xi = 0:dx:200e3;
zi = 0:dz:6e2;
m=length(zi);%domain dimension
n=length(xi);%domain dimension
%%%max z where the slope starts
zs = find(zi==max(zi));
for ii=1:n %for every x
zslope = -a*xi(ii)+zi(zs);%equation of the slope
zz(ii)=zslope;
if zslope>=0 %if the slope is still in the domain (z>0)
for jj=1:m %for every z
if zi(jj)>=zslope %above the slope
Z(jj,ii) = zi(jj)-zslope; %height above the slope
elseif zi(jj)<zslope %below the slope (ground)
Z(jj,ii)=NaN;
end
end%for on z
elseif zslope<0 %the slope is no longer in the domain
for jj=1:m %for every z
Z(jj,ii) = zi(jj)-zslope; %height above the slope
end
end
end%for on x
这似乎工作正常:
figure;
imagesc(Z)
colorbar
事实上,点 240 的值正如人们所期望的那样是 600。
问题
问题是在工作区中 Z
矩阵充满了 NaN
s!
当值是 NaN
时,imagesc
如何不显示 NaN
值?
注意
如果我评论这些行
elseif zi(jj)<zslope %below the slope (ground)
Z(jj,ii)=NaN;
没问题。
NaN
显示为颜色条中的最低值(反之亦然)。如果要从图中删除 NaN 值,可以使用 isnan
和 AlphaData
属性.
imagesc(Z,'AlphaData',~isnan(Z))