%------------------------
% one example of surface
[X,Y] = meshgrid(-2:.2:2, -2:.2:2);
Z = X .* exp(-X.^2 - Y.^2);
%---------------------
eb_id= [1,1;...
17,6]; % errorbar index of X Y coordinates
x_eb_id=X(eb_id(:,1)); % X coordinates of the points with errorbars
y_eb_id=Y(eb_id(:,2)); % Y coordinates of the points with errorbars
for i=1:length(x_eb_id)
z_eb_id(i)=Z(eb_id(i,2),eb_id(i,1)); % Z coordinates of the points with errorbars
end
eb_E=[0.2,0.2]; % Error
figure
surf(X,Y,Z)
hold on
plot3_errorbars_surf(x_eb_id,y_eb_id,z_eb_id,eb_E);
%-----------------------------------------------
function [h]=plot3_errorbars_surf(x, y, z, e)
% this matlab function plots 3d data using the plot3 function
% it adds vertical errorbars to each point symmetric around z
% I experimented a little with creating the standard horizontal hash
% tops the error bars in a 2d plot, but it creates a mess when you
% rotate the plot
%
% x = xaxis, y = yaxis, z = zaxis, e = error value
% create the standard 3d scatterplot
hold on;
h=plot3(x, y, z, '.k');
% looks better with large points
set(h, 'MarkerSize', 25);
hold on
% now draw the vertical errorbar for each point
for i=1:length(x)
xV = [x(i); x(i)];
yV = [y(i); y(i)];
zMin = z(i) + e(i);
zMax = z(i) - e(i);
zV = [zMin, zMax];
% draw vertical error bar
h=plot3(xV, yV, zV, '-k');
set(h, 'LineWidth', 2);
end
res.jpg