Difference between plotting 3D Graphs (Curve vs Area)
10 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
採用された回答
Divija Aleti
2021 年 4 月 22 日
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.
Hope this helps!
Thanks,
Divija
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Surface and Mesh Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!