Contour plot not working (but contour3 plot does work)

37 views (last 30 days)
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.

Accepted Answer

David (degtusmc)
David (degtusmc) on 5 Sep 2013
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.

More Answers (1)

Richard McCulloch
Richard McCulloch on 27 Jul 2013
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 Comments
Richard McCulloch
Richard McCulloch on 29 Jul 2013
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) on 1 Aug 2013
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.

Sign in to comment.

Categories

Find more on Contour Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!