How to append number to array
29 views (last 30 days)
Show older comments
I am new to Matlab.
S0=30;
K=32;
r=0.03;
sigma=0.2;
T=1;
M=10;
error=[];
for i=10:10:360
cat( TRGbinomial(S0,K,r,sigma,T,i)-BSCall(S0,K,r,sigma,T),error);
end
error
I want to append the number to error array.
What can I do with it?
2 Comments
Luna
on 14 Feb 2019
What are the TRGbinomial and BSCall functions outputs? Share the whole code please.
Accepted Answer
Luna
on 14 Feb 2019
Assuming that your function's outputs are 1x1 double, you can use below:
S0=30;
K=32;
r=0.03;
sigma=0.2;
T=1;
M=10;
% error=[];
j = 1; % another counter for for loop because i is used for another calculation
errorArray = zeros(360/10,1); % preallocation
for i=10:10:360
errorArray(j) = TRGbinomial(S0,K,r,sigma,T,i)-BSCall(S0,K,r,sigma,T);
j = j+1;
end
% errorArray will be 36x1 array.
More Answers (0)
See Also
Categories
Find more on Financial Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!