MATLAB: Index Exceeds Matrix Dimentions

errorscript

Ive written the following script
function futureworth(p,i,n)
nn=0:n; %lets the exponent know that its a matrix from 0 to n
F = p*(1+i).^nn;
y=[nn;F]; %displays table with the year and future worth
fprintf('Year Future Worth');
fprintf('%5d %14.2f\n',y);
end
But when I type "futureworth(100000,0.05,10)" in the command window I immediately get the error message "index exceeds matrix dimensions"
If anyone has any solutions to my problem please help!

Best Answer

You have to save it in your MATLAB user file path in its own .m-file as futureworth.m
If you created a variable named ‘futureworth’, you have to clear it first. See if:
clear futureworth
futureworth(100000,0.05,10)
works.
Related Question