Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何修改下面的代码以使用for循环绘制等高线标高?_Matlab_Matlab Figure_Contourf - Fatal编程技术网

Matlab 如何修改下面的代码以使用for循环绘制等高线标高?

Matlab 如何修改下面的代码以使用for循环绘制等高线标高?,matlab,matlab-figure,contourf,Matlab,Matlab Figure,Contourf,下面的代码在Zlevel指定的Z轴上的不同位置绘制多个等高线图。但是,我有多个感兴趣的Z数据点,因此我想使用for循环 Zlevel=[0 1]; figure(1) hold on [~,h1]=contourf(xx,yy,zz(:,:,1)); h1.ContourZLevel=Zlevel(1); hold on [~,hh1]=contour(xx,yy,yy); hh1.ContourZLevel=h1.ContourZLevel; hold on [~,h2]=cont

下面的代码在Zlevel指定的Z轴上的不同位置绘制多个等高线图。但是,我有多个感兴趣的Z数据点,因此我想使用for循环

Zlevel=[0 1];

figure(1)
hold on 
[~,h1]=contourf(xx,yy,zz(:,:,1)); h1.ContourZLevel=Zlevel(1);
hold on 
[~,hh1]=contour(xx,yy,yy); hh1.ContourZLevel=h1.ContourZLevel;  
hold on 
[~,h2]=contourf(xx,yy,zz(:,:,2)); h2.ContourZLevel=Zlevel(2);
hold on 
[~,hh2]=contour(xx,yy,yy);hh2.ContourZLevel=h2.ContourZLevel;
hold off
我在想我可以有这样的东西:

figure(1); hold on;
for i=1:length(Zlevel)
    [~,h(i)]=contourf(xx,yy,zz(:,:,i)); h(i).ContourZLevel=Zlevel(i); 
    hold on
    [~,hh(i)]=contour(xx,yy,yy); hh(i).ContourZLevel=Zlevel(i);
    hold on 
end
hold off
我试过了,但没法成功。我可能不理解matlab的对象处理。因此,如果有人能帮助我,向我解释为什么我不能做我想做的事情,并为我指出正确的方向,我将非常感激


谢谢

我不太明白为什么每个绘图需要两次调用
contourf
,因为secodn只会在图像上创建一些不好的线条

这是你想要的吗

% dummy data
[xx,yy,zz] = peaks;
zz(:,:,2)=-zz(:,:,1);
zz(:,:,3)=-2*zz(:,:,1);
zz(:,:,4)=2*zz(:,:,1);



Zlevel=[0 0.25 0.5 1];

figure(1)
hold on
for ii=1:length(Zlevel)
    [~,h(ii)]=contourf(xx,yy,zz(:,:,ii)); h(ii).ContourZLevel=Zlevel(ii);

end
view(3)

什么不起作用?结果不是你期望的吗?你有错误吗?你能提出你的问题并详细说明你希望情节是什么样子,以及什么东西没有按照你的意愿运作吗我可能不理解matlab的对象处理。你应该能够将图形句柄放在一个数组中,并像你正在做的那样设置属性,所以这可能不是问题。你会得到什么错误?