function newcell = Direction(cell, displacement)

% Diffusion direction
newcell = [cell 0];

% Left rate % Right rate % Up rate % Down rate
left = 0.25; right = 0.25; up = 0.25; down = 0.25;

% Edges
if cell(1, 1) == 1
    left = 0;
end

if cell(1, 1) == 5
    right = 0;
end

if cell(1, 2) == 1
    down = 0;
end

if cell(1, 2) == 5
    up = 0;
end

% Total rate
direction = up + down + left + right;

% Direction
random = rand(1);
if random < left/direction
    newcell(1, 1) = newcell(1, 1) - displacement;
    newcell(1, 3) = 1;
else
    if random >= left/direction && random < (left + right)/direction
        newcell(1, 1) = newcell(1, 1) + displacement;
        newcell(1, 3) = 2;
    else
        if random >= (left + right)/direction && random < (left + right + down)/direction
            newcell(1, 2) = newcell(1, 2) - displacement;
            newcell(1, 3) = 3;
        else
            if random >= (left + right + down)/direction
                newcell(1, 2) = newcell(1, 2) + displacement;
                newcell(1, 3) = 4;
            end
        end
    end
end



