function [reward,newstate] = gridworldStep(world,state,action) reward = getReward(world,state,action); %look up reward for this state-action pair %determine new state dim = ceil(action/2); %which dimension the action is on dir = mod(action,1 function reward = getReward(world,state,action) stateActionString = ''; %build text representation of state coordinates (workaround for limitations of matlab syntax) for d=1:length(state) stateActionString = [stateActionString num2str(state(d)) ',']; end stateActionString = [stateActionString num2str(action)]; reward = eval(['world( ' stateActionString ')']); %reward of taking action in state