The function cut_out

%this function converts the global configuration representation to a local
%ball view around a central agent. the function has input being the position vector pos_vec and state vector
%state_vec, the agent center_agent around which the ball is to be computed,
%and r, the radius

pos_vec = [1 3 4 6 11 13];
state_vec = [1 1 4 2 3 1];
center_agent = 3;
r = 3;

midpos  = pos_vec(center_agent); % this computes the position of agent "center_agent", setting the mid position of the ball
b = zeros(1,2*r+1); %this sets up a blank place holder

for i = 1:(2*r+1) %2r+1 is the size of the window of perception r steps to the left and right of the middle position

    [inval,agent_number] = ismember(midpos-(r+1)+i,pos_vec); %this computes whether there is an agent at position midpos-r-1+i, and so, which agent it is,
    %when counting from the left

    if (inval)
        b(i) = state_vec(agent_number);
    end

end

b
b =

     1     0     1     4     0     2     0