Matlab plot won't return correct results -


i have written function beginning of poisson process

function n_t = poisproc2(t,tao,size)  n_t=0;  n=1:size      if t>tao(1,n)         n_t=n_t+1;     end  end   end 

tao array of random doubles of length size. simplicity we'll [1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,20]

so functions purpose count how many elements of tao t greater given t.

this code works fine when write

poisproc2(3,tao,20); 

the answer 19 expected, if write

x=1:.01:20; y=poisproc2(x,tao,20); plot(x,y,'-') 

y shows 0 in workspace (i expect array of length 1901) , plot reads 0. i'm pretty new matlab, seems pretty thing i'm trying , must missing obvious. please help!

your code not work giving vector. if condition not working expect.

first initialize n_t vector :

n_t=zeros(1,length(t)) 

instead of

if t>tao(1,n)     n_t=n_t+1; end 

vectorize expression :

n_t = n_t + (t>tao(1,n)) 

cheers


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -