how to convert a 3D surface into a 2D contour?

5 ビュー (過去 30 日間)
Ramina
Ramina 2024 年 1 月 27 日
回答済み: Sulaymon Eshkabilov 2024 年 1 月 28 日
Hi,
I have a 3D surface(download: https://uploadkon.ir/uploads/9ced27_24input.zip) and I want to convert it into a 2D contour like the image below. but I dont know how.
ps: the colorbar in the 2D plot shows the variation of y-axis in the 3D plot.
  1 件のコメント
Torsten
Torsten 2024 年 1 月 27 日
I'd just change the view to be frontal on the xz-plane when plotting the surface :-)

サインインしてコメントする。

回答 (2 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024 年 1 月 27 日
This is how it can be done:
H = openfig('ds2.fig'); % This is the extracted plot figure
h = findobj(gca, 'Type', 'surface');
X = get(h, 'XData'); % Extract XData
Y = get(h, 'YData'); % Extract YData
Z = get(h, 'ZData'); % Extract YData
figure
plot(X, Z)
plot(X, Z)
xlabel("X")
ylabel("Z")
grid on
  1 件のコメント
Ramina
Ramina 2024 年 1 月 28 日
編集済み: Ramina 2024 年 1 月 28 日
Hi, thank you for the time you took to answer my question.
I want to show the collors (like the 2D plot in my question) as well to show the variation of y-axis. Can you help me to do that as well?
Here is the code I wanted to use, but it shows this error:
Error using contourf
Z must be at least a 2x2 matrix.
Error in contour_2D (line 4)
[~, hc] = contourf(h.XData, h.ZData, h.YData);
uiopen('fig adress',1)
h = findobj(gcf,'type','surface')
figure
[~, hc] = contourf(h.XData, h.ZData, h.YData);
h2=colorbar;

サインインしてコメントする。


Sulaymon Eshkabilov
Sulaymon Eshkabilov 2024 年 1 月 28 日
Note that it is clear from the colorbar scale (Figure 2 in your question) that there must be another operation before obtaining the plot (Figure 2 in your question) that is missing in your question.
Anyhow, here is another way of getting a similar plot.
H = openfig('ds2.fig'); % This is the extracted plot figure
view(360,0)
xlabel("X")
zlabel("Z")
grid on
xlim([0, 2])

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by