I have removed what is not needed in your code. I was able to code this function in 9 lines, it needn't be very long
.
Realize what we are trying to do here: we are simulating numsum "sample paths". Therefore we will have a matrix that is 10 x numsum, with each column corresponding to a "sample path". We can then do a cumprod on each column, leaving us a 1 x numsum matrix of "payoffs". If it makes you feel more comfortable you can use for loops instead of cumprod, but it will be much slower in matlab.
%function to price non standard option using monte carlo
function [C,Cl,Cu] = assignment(S0,Rt,T,sigma,delta, numsim)
%S0=initial stock price, Rt=excess return over risk free rate, T=time,
%sigma=volatility,numsim=number of simulations, delta=devidend yield
R=0.03;%risk free rate is constant over lifetime of option
delta=0.02;%dividend given
r=log(1+R);
%put mat definition here (using my suggestion for matrix of random variables)
Rt=exp(r-delta-0.5*sigma*sigma+sigma*mat)-1;
%put code for max(Rt, R) and cumprod("result") here
g=exp(-r*T)*payoffs;
C=mean(g);s=std(g);
Cl=C-1.96/sqrt(numsim)*s;
Cu=C+1.96/sqrt(numsim)*s;