First of all I'm new to matlab and this forum so excuse my ignorance.
I generate a standard wiener process in the following way (I made it up myself, so if it's stupid or wrong I would like to know).
s =0.0001; % stepsize
t = [0:s:T]; % divide interval into steps
G=sqrt(s)*randn(length(t),1);
Y=cumsum(G);
Now I want to find its values at some random times, say:
u=rand(4,1)
I figured out (with google and patience) to do something like
for i = 1:length(u)
row(i) = find(t < u(i),1,'last');
end
and then simply take out the values from Y, but I would like to find a more direct way - do you have any suggestions?
What you're basically doing for each element in u
is finding the index of the largest element in t
. Try the following one-liner:
sum(bsxfun(@lt, repmat(t(:)', numel(u), 1), u(:)), 2)
What this does is:
repmat
, where each row equals t
.bsxfun
for elements less than the corresponding element in u
.By the way, there is no need to put brackets ([]
) in t = [0:s:T]
. The colon operator (:
) already outputs a vector.