SHARE
TWEET

neighbor8

a guest Sep 19th, 2019 99 in 280 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function y=neighbor8(x)
  2. % Troca um membro com seu proximo
  3.     index = randi(length(x));
  4.     swap = randi([0,1]); % Swap for the next or previous
  5.     aux = x(index);
  6.     y = x;
  7.     if(index < length(x) && swap == 1)
  8.         y(index) = x(index+1);
  9.         y(index+1) = aux;
  10.     elseif (index == length(x) && swap == 1)
  11.         y(index) = x(1);
  12.         y(1) = aux;
  13.     elseif (index > 1 && swap == 0)
  14.         y(index) = x(index-1);
  15.         y(index-1) = aux;  
  16.     elseif (index == 1 && swap == 0)
  17.         y(index) = x(length(x));
  18.         y(length(x)) = aux;
  19.     end
  20. end
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
 
Top