簡體   English   中英

MATLAB 3D曲線圖

[英]MATLAB 3D Plotting of Curves

我要嘗試繪制2個變量,但無法弄清楚要使用哪些函數才能獲得所需的圖形。 例如,我有一個變量Depth,它是一個充滿數字的70x12矩陣。 每年的每個月12個。 我正在嘗試針對溫度繪制深度,這也是一個70x12的數字矩陣。 我目前這樣做的方法是在for循環中使用plot3並保持不變,並在z軸上繪制每個以1分隔的深度與溫度曲線。 看起來像這樣:

當旋轉時,它看起來像這樣:

但是,我想要的是曲線之間的某種網格或沖浪,以便圖形看起來與此相似。 我在網上沖浪並進行了不錯的划分,但我不知道如何使用存儲在變量中的數據來繪制曲線和通過曲面的曲面,看起來像這樣。

在此處輸入圖片說明

您可以使用plot3surf進行plot3 ,但是強烈建議使用plot3創建深度,溫度和月份的矩陣。

以下代碼顯示了如何執行此操作。 我只是做了一些所謂的任意溫度數據temps ,然后用meshgrid把深度和個月的載體導入對應於臨時工每個條目的網格。 請注意,由於MD現在是矩陣,所以不需要for循環,只需一次plot3所有3矩陣即可。

% create some data. The problem is that depths and months are vectors while
% I have a 70x12 grid o temperatures:
nd = 70;
depths = linspace(0, 1e3, nd);
months = 1:12;
temps = sin((1:nd)'*months/(nd*8));


% So make temps and depths matrices too:
[M, D] = meshgrid(months, depths)

% and now plot:
figure(112)
clf

% plot the surface from the matrices returned by meshgrid: notice I used
% facealpha to change the transparency:
hs = surf(temps, D, M, 'facealpha', .5);
hold all;

% now that we used meshgrid we can plot everything at once:
plot3(temps, D, M, 'linewidth', 3)

view(3)
grid on

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM