Contour plot not working (but contour3 plot does work)

조회 수: 48 (최근 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 CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by