从学长那里获得了以下代码老是报错32行Function definitions are not permitted in this context.
clear;clc;
disp('A*开始搜索路径......')
%% 画一个方形地图
map.XYMAX=50; % 地图尺寸
map.start=[5,1]; % 起点坐标
map.goal=[45,45]; % 终点坐标
genGrid(map); % 绘制地图
hold on;
obstacle = GetBoundary(map); %边界数据
nObstacle = 60; %在地图中随机加入XX个障碍物
obstacle = GetObstacle(nObstacle,obstacle,map);%障碍物和边界坐标
obstacle = [obstacle;10 4;10 5;10 6;10 7;10 8];
obstacle = [obstacle;11 4;11 5;11 6;11 7;11 8];
obstacle = [obstacle;12 4;12 5;12 6;12 7;12 8];
obstacle = [obstacle;13 4;13 5;13 6;13 7;13 8];
obstacle = [obstacle;20 20;20 19;20 18;20 17;];
obstacle = [obstacle;25 20;25 19;25 18;25 17;25 16;25 15;25 14;25 13;25 21;25 22;25 23;25 24;25 25;25 26;25 28;25 27];
obstacle = [obstacle;25 29;25 30;25 31;25 32;25 33;25 34;25 38];
%% 画出障碍点
fillPlot(obstacle,[0 0 0]);
%% 调用算法画出路径
path=AStar(obstacle,map);%A*算法
if length(path)>=1
plot(path(:,1),path(:,2),'Color','y','LineWidth',2);
end
%% 获得地图的边界的坐标
function boundary=GetBoundary(map)
boundary=zeros((map.XYMAX+2)*4,2);
for i1=0:(map.XYMAX+1)
boundary(i1+1,:)=[0 i1];
end
for i2=0:(map.XYMAX+1)
boundary(i2+i1+1,:)=[i2 0];
end
for i3=0:(map.XYMAX+1)
boundary(i3+i2+i1+1,:)=[map.XYMAX+1 i3];
end
for i4=0:(map.XYMAX+1)
boundary(i4+i3+i2+i1+1,:)=[i4 map.XYMAX+1];
end
end
%% 随机生成障碍点的坐标集合
function obstacle=GetObstacle(nob,obstacle,map)
ob = round(rand([nob,2])*map.XYMAX);
% 生成的障碍点有可能是和start点和goal点坐标重合的,
% 需要删除,removeInd为重合点的数组索引index
removeInd=[];
for io=1:length(ob(:,1))
if(isequal(ob(io,:),map.start) || isequal(ob(io,:),map.goal))
removeInd=[removeInd;io];
end
end
ob(removeInd,:)=[];
obstacle=[obstacle;ob];
end
跪求大佬解答如何解决。