www.gusucode.com > robotics 案例源码程序 matlab代码 > robotics/CreateAndModifyAnOccupancyGridExample.m

    %% Create and Modify Occupancy Grid  

%% 
% Create a 10m-by-10m empty map. 
map = robotics.OccupancyGrid(10,10,10);  

%% 
% Update the occupancy of world locations with specific probability values.  
map = robotics.OccupancyGrid(10,10,10);
x = [1.2; 2.3; 3.4; 4.5; 5.6];
y = [5.0; 4.0; 3.0; 2.0; 1.0];

pvalues = [0.2 0.4 0.6 0.8 1];

updateOccupancy(map,[x y],pvalues)
figure
show(map)  

%% 
% Inflate occupied areas by a given radius. Larger occupancy values
% overwrite the smaller values.
inflate(map,0.5)
figure
show(map)  

%% 
% Get grid locations from world locations. 
ij = world2grid(map,[x y]);  

%% 
% Set grid locations to occupied locations. 
setOccupancy(map,ij,ones(5,1),'grid')
figure
show(map)