3D surface plots from 3 vectors?

4 views (last 30 days)
Adam Silva
Adam Silva on 15 Mar 2015
Edited: Adam Silva on 16 Mar 2015
I have 3 vectors. v1, v2, and v3. All are vectors with n number of elements in them. How to draw a surface plot. Matlab asking to make the Z axis a square matrix. Is there a way to represent the v3 matrix in matrix form? So we can create the Z bus matrix ad use 'surf' command?

Accepted Answer

John D'Errico
John D'Errico on 15 Mar 2015
Download my gridfit code from the file exchange. Or use scatteredInterpolant or griddata to interpolate onto a grid. Or use triangulation based tools like delaunay to trinagulate the set in the (x,y) plane, then use trisurf.
IMHO, gridfit is the best solution most of the time. But then I might be biased. :)
  3 Comments
John D'Errico
John D'Errico on 15 Mar 2015
Edited: John D'Errico on 15 Mar 2015
What you need to understand is that when you use the colon operator, AND the lower limit is higher than the upper limit, AND the step is positive, you get this...
gy=1.019:0.0005:1.015
gy =
Empty matrix: 1-by-0
What do you expect to happen?
gx=0.15:0.0005:65.05;
whos gx gy
Name Size Bytes Class Attributes
gx 1x129801 1038408 double
gy 1x0 0 double
Next, do you REALLY need to have that fine of a step in x? I'm sorry, but that is simply silly.
If you did swap the limits on gy (so there would now be only 9 steps in y), most likely your next question will be why do you get out of memory errors, or why does it take forever to terminate. You simply don't have sufficient data to justify that fine of a grid. As you say, you have only 50 data points in total.
AND, if gridfit did successfully terminate, then when you tried to plot a 129891x72 array as a surface plot, your next question will probably be "Why does MATLAB crash when I try to plot?" Or possibly it will just take forever to generate that plot.
Regardless, your screen does not have that much resolution. Even if you have a 40 inch monitor, there are only a few thousand pixels across it. Trying to plot something that is that large is a waste of CPU resources.
Next, consider your eyes. Your own eye simply lacks the capability to resolve that fine of a grid. There are only so many cones in your eye.
How about if you did manage to create that surface which was of size 129801 by 9? My guess is the surface plot will look quite strange, with such a low resolution in one dimension compared to the other.
So I would strongly suggest you reduce the size of your grid in y, and increase it in x. Even 1000 steps in x is still seriously more than your eye can see as a smooth function. Several hundred step is far more reasonable, and gridfit will generate that surface in the blink of an eye, and probably in less time than your computer will take to plot it anyway.
Computers are not infinitely fast nor are they infinitely powerful. Monitors are impressive, but they are limited. And well, your eye is not that good either, unless of course, your name happens to be Clark Kent.
My recommendation, IF you want to get something that looks even mildly meaningful, you might consider something vaguely like this:
gx=0.15:0.05:65.05;
gy=1.015:0.000025:1.019;
whos gx gy
Name Size Bytes Class Attributes
gx 1x1299 10392 double
gy 1x161 1288 double
At least as a start. Even that might look lopsided, and it is far more fine than 50 data points can justify.
Adam Silva
Adam Silva on 16 Mar 2015
Edited: Adam Silva on 16 Mar 2015
I really appreciate the detailed explanation. It helped me to improve the way I code in Matlab.
Your recommendation regarding the changes I should make to the code worked.
Thank you

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!