Can't colour a 3D map?

Please help, I have got the 3D graph, and I want to colour it according to its Z-axis value.
%------------------------------------------------------------------------------------------------------
%Function:
function C = bs ( Interest, Volatility, Stock, StrikePrice, TimeToMaturity )
d1 = (log(Stock ./ StrikePrice) + (Interest + (Volatility .^ 2) ./ 2) .* TimeToMaturity) ./ (Volatility .* sqrt(TimeToMaturity));
d2 = (log(Stock ./ StrikePrice) + (Interest - (Volatility .^ 2) ./ 2) .* TimeToMaturity) ./ (Volatility .* sqrt(TimeToMaturity));
C = normcdf(d1) .* Stock - normcdf(d2) .* StrikePrice .* exp(-Interest .* TimeToMaturity);
end
%------------------------------------------------------------------------------------------------------
%Code:
stock = 0 : 0.01 : 1100;
time = 0/52 : 1/52 : 9/52;
[X, Y] = meshgrid(stock, time);
Z = bs(0.05, 1.13, X, 800, Y);
surf(X, Y, Z)
colormap hsv
colorbar
xlabel('Stock Price')
ylabel('Time')
zlabel('Option Price')
grid on
%------------------------------------------------------------------------------------------------------
Thank you very much!

Answers (1)

Walter Roberson
Walter Roberson on 5 Feb 2014

0 votes

By default surf() already colors according to Z axis value.

2 Comments

Thank you for your answer. However, after implementing the code, why my 3d plot have no colour?
Sorry I do not have the Stats toolbox to test the code with.
Does the same problem occur if you leave out the "colormap" command?
Is your surface showing up flat? If it is then your Z might be constant.

Sign in to comment.

Asked:

on 4 Feb 2014

Commented:

on 5 Feb 2014

Community Treasure Hunt

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

Start Hunting!