Difference between plotting 3D Graphs (Curve vs Area)
9 ビュー (過去 30 日間)
Niklas Kurz 2021 年 4 月 19 日
回答済み: Divija Aleti 2021 年 4 月 22 日
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
[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
Divija Aleti 2021 年 4 月 22 日
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;
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;
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.
Hope this helps!
その他の回答 (0 件)
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!