Difference between plotting 3D Graphs (Curve vs Area)

8 visualizzazioni (ultimi 30 giorni)
I discovered 2 plotting methods that I can't really distinguish:
[x] = meshgrid(-1:0.1:1)
y = x.^2;
z = x;
surf(x,y,z)%plots a curve
and
[x,y] = meshgrid(-1:0.1:1)
z = x;
surf(x,y,z)%plots an area
Why they are so different? The curve seems like a product that can be achieved with
plot3

Risposta accettata

Divija Aleti
Divija Aleti il 22 Apr 2021
Hi Niklas,
Firstly, the difference in the two surf plots is because the matrix 'y' is different in both the cases.
To understand the difference between 'surf' and 'plot3', take a look at the following example. (I have renamed 'y' as 'y1' and 'y2' as both the values are different). Let's start with the second method.
[x,y2] = meshgrid(-1:0.1:1);
z = x;
plot3(x,y2,z,'-o')
figure
surf(x,y2,z)
Output:
For both plot3 and surf, the corresponding points in the x, y2 and z matrices are plotted. Then, in 'plot3', all points corresponding to the first column of the matrices are joined, those corresponding to the second column of the matrices are joined and so on, thus giving us the first plot shown above. In 'surf', along with joining the columns, the points corresponding to the rows of the matrices are also joined giving us a surface as shown above in the second plot.
Now, coming to the first method.
[x] = meshgrid(-1:0.1:1);
y1 = x.^2;
z = x;
plot3(x,y1,z,'-o')
figure
surf(x,y1,z)
Output:
Similar to the previous method, for both plot3 and surf, the corresponding points in the x, y1 and z matrices are plotted. Now, in 'plot3', the points corresponding to the same column of the matrices should be joined. But, if you look at the matrices, you will find that for each matrix, all the rows in a column have the same value, hence it is a single point, and therefore there is no line - refer to the first plot shown above. In 'surf',as usual, the points corresponding to the rows of the matrices are joined, which in this case gives us a curve as we are just joining single points together.
For additional information on the functions, refer to the following links: meshgrid, surf, plot3
Hope this helps!
Thanks,
Divija

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by