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

1 view (last 30 days)
xiaofu li on 27 Jan 2020
Answered: Cameron B on 28 Jan 2020
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 on 28 Jan 2020
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)