function [x y] = DiffusionMemPos(N,membrane,permeability,position) % N is a positive integer. % Simulates a 2D Diffusion with semipermeable membrane % x and y are row vectors with the property that (x(k),y(k)) is the % location of the token after N Time. %Membrane is where the molcules cannot cross %Permeability is the permeability of the membrane to that molecule %Position is whether it starts inside or out of the cell % Initializations... if (strcmp('In',position)) k = 0; xc = -10; yc = 0; else k=0; xc=10; yc=0; end % In general, (xc,yc) is the location after N time. % Boundary xMinBoundary=-20; xMaxBoundary=20; yMinBoundary=-20; yMaxBoundary=20; while kpermeability) xc = xc - 1; else xc = xc +1; end end else if (rand < .5)&&(yc < yMaxBoundary-1) yc = yc + 1; else if yc~=yMinBoundary+1 yc = yc - 1; else yc = yc +1; end end end % Save location... k = k + 1; x(k) = xc; y(k) = yc; end % while k