Lab2 Matlab Code

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

clear all

% size of map on x-axis


x_max=10;

%size of map along y-axis


y_max=10;

% x-coordinate of start position


x_s=1;

% y coordinate of the start position


y_s=1;

% x-coordinate of the target point


x_t= 10;

% y-coordinate of the target point


y_t=10;

% create a matrix filled with zeros


Map= zeros(x_max, y_max);

% define obstacle's origin


obstacle_origin = [3 3];

% size of the obstacle


obstacle_size = [5 5];

% fill the map with the obstacle


for i = obstacle_origin(1): obstacle_origin(1)+ obstacle_size(1)
for j = obstacle_origin(2) : obstacle_origin(2) + obstacle_size(2)
Map(i,j) = 1;
end
end

% fill the map with the start point


Map(x_s,y_s)= 2;

% fill the map with the target point


Map(x_t,y_t) =3;

% plot the map along with obstacle, start point and target point
figure
grid on
hold on

% draw the obstacle using patch command


patch( [obstacle_origin(1) obstacle_origin(1)+obstacle_size(1)
obstacle_origin(1)+obstacle_size(1) obstacle_origin(1)], [obstacle_origin(2)
obstacle_origin(2) obstacle_origin(2)+obstacle_size(2)
obstacle_origin(2)+obstacle_size(2)],'k');

% draw the location of start point


scatter(x_s-0.5, y_s-0.5,'o','r','filled');

% draw the target point


scatter(x_t-0.5,y_t-0.5,'o','g','filled');
% make the grid cells fixed length
set(gca,'xtick',0:1:x_max)
set(gca,'ytick',0:1:y_max)

%define start and ending of axis


axis([0 x_max 0 y_max])

You might also like