How can I create a 3D plot by using the surf?

2 次查看(过去 30 天)
The problem I am facing is that: I have 3 vectors which are time vector, displacement vector and the Probability density function(PDF) vector. at each time point, the mean and the variance of the PDF will be varied, therefore, I would like to create a 3D plot, the x axis is the displacement vector , the Y axis is the time vector and the Z axis is the corresponding PDF.
Disp_=linspace(-2,2,200);
var_disp=[0.0021 0.0023 0.0025 0.0026 0.0029 0.0030 0.0031 0.0032 0.0035 0.0037]; % Variance vector
ave_disp=[0.01 0.02 0.03 0.03 0.05 0.06 0.04 0.05 0.07 0.09]; % mean vector
timeVector_=linspace(0,2,10); % time vector
PDF=nan(length(Disp_),length(timeVector_));
for ii=1:10
PDF(:,ii)=1/(sqrt(2*pi*var_disp(ii)))*exp(-1/2*(Disp_-ave_disp(ii)).^2/(var_disp(ii)));
end
surf(Disp_,timeVector_,PDF)
I tried with multiple solutions(also the plot3 command), but none of them works for what I expect. any help from anyone will be very grateful.

采纳的回答

Cameron B
Cameron B 2020-1-28
You could get better resolution if you had more points in your var_disp and ave_disp vectors. I suppose you could interpolate, but that’s not really going to be too much help. Either way, I’m not sure this is what you wanted, but here’s what I did:
Disp_=linspace(-2,2,10);
var_disp=[0.0021 0.0023 0.0025 0.0026 0.0029 0.0030 0.0031 0.0032 0.0035 0.0037]; % Variance vector
ave_disp=[0.01 0.02 0.03 0.03 0.05 0.06 0.04 0.05 0.07 0.09]; % mean vector
timeVector_=linspace(0,2,10); % time vector. PDF=nan(length(Disp_),length(timeVector_));
for ii=1:10
PDF(:,ii)=1/(sqrt(2*pi*var_disp(ii)))*exp(-1/2*(Disp_-ave_disp(ii)).^2/(var_disp(ii)));
end
surf(Disp_,timeVector_,PDF)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by