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

    %% Create Occupancy Grid from 2-D Map
% 
%%
% Load two maps, |simpleMap| and |complexMap|, as logical matrices. Use 
% |whos| to show the map.
filePath = fullfile(fileparts(which('PathPlanningExample')),'data','exampleMaps.mat');
load(filePath)
whos *Map*

%%
% Create a ROS message from |simpleMap| using a |BinaryOccupancyGrid|
% object. Write the |OccupancyGrid| message using |writeBinaryOccupancyGrid|. 
bogMap = robotics.BinaryOccupancyGrid(double(simpleMap));
mapMsg = rosmessage('nav_msgs/OccupancyGrid');
writeBinaryOccupancyGrid(mapMsg,bogMap)
mapMsg

%%
% Use |readBinaryOccupancyGrid| to convert the ROS message to a 
% |BinaryOccupancyGrid| object. Use the object function |show| to display the map.
bogMap2 = readBinaryOccupancyGrid(mapMsg);
show(bogMap2);