Hi, I'm trying to make a boundry that reflects the integrin to the opposite side of where the boundary touches, for instance it hits the top and ends up on the bottom.
    8 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
N=10; % number of integrins
L=100; % size of the domain 100nm
D=.01; % diffusion coefficient
dt=1; % time step
F=randi([1, 10],1); % force on the bond with a random number of 1 to 10
P_a=randi([0,1],1); % binding rate of a random number from 0 to 1
P_ub=1/(1.5*F); % unbinding rate based upon our previous values
Tmax=500; % max time
% Intialize our integrins
x=randi([0,360],N,1); % x-coordinates generated randomily for each integrin
y=randi([0,50],N,1); % y-coordinates generated for each 
state=ones(N,1); % Each integrin is set to an inactive state at 0
% our figure
figure;
axis([0 L 0 L]);
set(gca,'nextplot','replacechildren');
% position update
for t = 0:dt:Tmax
     for i=1:N
         w=randi([0,1],1); 
         if state(i)==1
         dx=randi([-360,360],1);
         dy=randi([-50,50],1);
         x(i)=x(i)+dx;
         y(i)=y(i)+dy; 
         end 
     end
     for i=1:N
         w=randi([0,1],1);
         if w < P_a && state(i)==1
             state(i)=2;
             colors(i,:)=[0 1 0]; % Turn it to green
         end
     end
     for i=1:N
         w1=randi([0,1],1);
         if state(i)==2 && w1<P_ub
            state(i)=1;
         end
     end
     % colors for our integrin states
colors = repmat([1 0 0], N,1); % red for inactive state
colors(state == 1,:,:) = repmat([0 1 0],sum(state == 1),1);
    % plotting our integrins
    scatter(x,y,100,colors,'filled');
    title(sprintf('Time=%.2f',t));
    drawnow;
     colors(i,:)=[0 0 1]; % Turn it back to red
     colors(i,:)=[0 1 0]; % Turn it to green
end
0 Commenti
Risposte (1)
  Vandit
    
 il 31 Mag 2023
        Hi,
The main modification is to reflect the integrins that hit the boundary. To do this, I added a nested for loop right after the initial for loop that updates the position of the integrins. In the new loop, I checked if the x or y coordinate of an integrin has gone out of bounds (less than 0 or greater than L), and if so, I reflected its position to the opposite side of the boundary.
Also the code you provided has some errors that need to be corrected. Kindly find the corrected code along with the modifications to reflect the integrins at the boundary given below:
N = 10; % number of integrins
L = 100; % size of the domain in nm
D = 0.01; % diffusion coefficient in nm^2/s
dt = 1; % time step in s
F = randi([1, 10], 1); % force on the bond with a random number of 1 to 10 pN
P_a = rand(1); % binding rate of a random number from 0 to 1
P_ub = 1 / (1.5 * F); % unbinding rate based on our previous values
Tmax = 500; % max time
% Initialize our integrins
x = randi([0, 360], N, 1); % initial x-coordinates randomly distributed
y = randi([0, 50], N, 1); % initial y-coordinates randomly distributed
state = ones(N, 1); % Each integrin is set to an inactive state at 0
colors = repmat([1 0 0], N, 1); % red for inactive state
colors(state == 1, :, :) = repmat([0 1 0], sum(state == 1), 1); % green for active state
% Create the figure
figure;
axis([0 L 0 L]);
set(gca, 'nextplot', 'replacechildren');
% Main time loop
for t = 0:dt:Tmax
  % Update the positions of the integrins
  for i = 1:N
    if state(i) == 1
      dx = sqrt(2 * D * dt) * randn(1); % Random displacement in x
      dy = sqrt(2 * D * dt) * randn(1); % Random displacement in y
      x(i) = x(i) + dx; % Update x-coordinate
      y(i) = y(i) + dy; % Update y-coordinate
    end
  end
  % Reflect integrins at the boundary
  for i = 1:N
    if x(i) < 0
      x(i) = -x(i);
    elseif x(i) > L
      x(i) = 2 * L - x(i);
    end
    if y(i) < 0
      y(i) = -y(i);
    elseif y(i) > L
      y(i) = 2 * L - y(i);
    end
  end
  % Update integrin states
  for i = 1:N
    if state(i) == 1
      if rand(1) < P_a % Probability of activation
        state(i) = 2; % Turn integrin active
        colors(i, :, :) = repmat([0 1 0], 1, 1, 3); % Update color to green
      end
    elseif rand(1) < P_ub % Probability of unbinding
      state(i) = 1; % Return integrin to inactive state
      colors(i, :, :) = repmat([1 0 0], 1, 1, 3); % Update color to red
    end
  end
  % Plot the integrins
  scatter(x, y, 100, colors, 'filled');
  title(sprintf('Time: %.2f s', t));
  drawnow;
end
Hope this helps.
Thankyou
0 Commenti
Vedere anche
Categorie
				Scopri di più su Gravitation, Cosmology & Astrophysics in Help Center e File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!