Contour plot not working (but contour3 plot does work)

24 ビュー (過去 30 日間)
David (degtusmc)
David (degtusmc) 2013 年 7 月 26 日
Hello everyone,
For some reason when I use the 'contour' function, it just gives me a blank figure. On the other hand, if I use 'contour3' it displays the 3-D contour plot. Any suggestions why this may be happening?
I have a 31x1 double (x-axis), a 19x1 double (y-axis), and a 31x19 double (z-axis).
- First, I use meshgrid with the x and y-axis, which gives me a 19x31 and 19x31 respectively.
- Next, I transpose the z-axis to obtain a 19x31 (just as the other 2 axis)
- Finally, I plot them and obtain the desired surface and mesh plots; but, I am unable to obtain the contour plot as I mentioned above.
Thank you in advance for any help provided.

採用された回答

David (degtusmc)
David (degtusmc) 2013 年 9 月 5 日
I am still not sure why the 'contour' function did not work for me. It must be some bug in my code.
I ended up using the 'contour3' function. To obtain the regular contour, I use the 'rotate 3D' toolbar and by right clicking on the plot it gives the option to "Go to X-Y view" which is the regular contour.

その他の回答 (1 件)

Richard McCulloch
Richard McCulloch 2013 年 7 月 27 日
From my understanding, meshgrid will create a matrix out of x and y to provide a 2 dimensional indexing for z. To get a simple 2D contour the vectors have to be the same size. This is because you are essentially defining a z value at an ordered pair (x,y). If the data is linear maybe look at linspace to make them all the same length.
  3 件のコメント
Richard McCulloch
Richard McCulloch 2013 年 7 月 29 日
Is your Z a single value? I am getting it to work fine with this example:
x=[1:31]'; y=[1:19]'; z=rand(31,19);
size(x), size(y), size(z)
ans =
31 1
ans =
19 1
ans =
31 19
[x,y]=meshgrid(x,y);
contour(x,y,z')
contour3(x,y,z')
Are any errors showing up? This is a unique problem it seems.
Richard
David (degtusmc)
David (degtusmc) 2013 年 8 月 1 日
To be completely honest I am not sure what is wrong with it. No errors are showing up and both surface and mesh plots work fine with the same data.
The weirdest part is that, when I went to check if any errors were showing, I commented out the 'contour3' function and replaced it with the regular 'contour' function. I ran it, and it worked!!! Then I deleted the 'contour3' (commented line) and ran it again, but this time it did not work and it has not work since then.
Thanks for the help though.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by