Can't colour a 3D map?

9 Ansichten (letzte 30 Tage)
Tiancong
Tiancong am 4 Feb. 2014
Kommentiert: Walter Roberson am 5 Feb. 2014
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!

Antworten (1)

Walter Roberson
Walter Roberson am 5 Feb. 2014
By default surf() already colors according to Z axis value.
  2 Kommentare
Tiancong
Tiancong am 5 Feb. 2014
Thank you for your answer. However, after implementing the code, why my 3d plot have no colour?
Walter Roberson
Walter Roberson am 5 Feb. 2014
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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by