SHARE
TWEET

matdiff

a guest Mar 27th, 2014 665 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %SIMULATION OF THE DIFFUSION PROCESS
  2. rtn=500; %num trials
  3. global rt;
  4. rt=zeros(2,rtn);
  5.  
  6. maxWalk=15000;
  7.  
  8. %PARAMETERS
  9. a=10; %positive boundary (the negative is 0)
  10. z=0;  %starting point
  11. s=1;%variance in drift rate within trial
  12. v=0.38;%mean drift rate
  13.  
  14. for xx=1:rtn
  15.     timeseries(1:maxWalk,1)=NaN;
  16.     timeseries(1)=z;
  17.    
  18.     for i=2:maxWalk
  19.         timeseries(i)=timeseries(i-1)+normrnd(v,s,1,1);
  20.         if (timeseries(i)>=a)
  21.                 %linear interpolation
  22.             slope=timeseries(i)-(timeseries(i-1));
  23.             x=i-(timeseries(i)-a)/slope;
  24.             rt(1,xx)=x;
  25.             break;
  26.         end
  27.        
  28.     end
  29.     if xx==1
  30.         plot([0 150],[1 1],'b:');
  31.     end
  32.     timeseries(isnan(timeseries))=[];
  33.     time=(1:length(timeseries));
  34.     figure(1); hold on; plot(time, timeseries,'r.-'); drawnow;
  35. end
  36.  
  37.  
  38. figure();
  39. RT{1}=rt(1,find(rt(1,:)>0));
  40.  
  41. %{
  42. [~,~,~,~,~,~,~,par]= myHist(RT{1},'binW',1, 'typePlot','h','fit','invg');
  43.  par{1}{1}
  44. %}
  45. mu=a/v; sig=a.^2./s.^2;
  46. %display(['Estimated - mu:' num2str(par{1}{1}(1)) ' s:  ' num2str(par{1}{1}(2))]);
  47. display(['Real - mu:' num2str(mu) ' s:  ' num2str(sig)]);
  48.  
  49. x=0:0.1:400;
  50. hold on; plot(x,invgpdf(x,mu,sig),'r-');
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top