【问题标题】:imagesc showing NaN values as not NaN [duplicate]imagesc 将 NaN 值显示为非 NaN [重复]
【发布时间】:2016-08-22 18:59:16
【问题描述】:

下图中的红色补丁显示了数值模型的域。绿色补丁显示的是地球。

我想为模型域中的点创建一个包含地球表面以上高度值的矩阵。

我使用以下代码:

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 矩阵充满了NaNs!

imagescNaNs 时如何不显示 NaN 值?

注意

如果我评论这些行

elseif zi(jj)<zslope %below the slope (ground)

     Z(jj,ii)=NaN;

没有问题。

【问题讨论】:

    标签: matlab nan


    【解决方案1】:

    NaN 在颜色栏中显示为最小值(相反)。如果您想从图中删除 NaN 值,您可以使用 isnanAlphaData 属性来实现。

    imagesc(Z,'AlphaData',~isnan(Z))
    

    【讨论】:

      猜你喜欢
      • 2016-11-19
      • 1970-01-01
      • 2017-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-17
      • 1970-01-01
      • 2021-12-30
      相关资源
      最近更新 更多