Maze Generation Algorithm Plotting Error

조회 수: 1 (최근 30일)
programmer_in_the_making
programmer_in_the_making 2021년 1월 12일
답변: Akanksha Shrimal 2022년 1월 27일
Hey guys, I'm trying to write a script that generates a maze. Normally it works fine, but when i try to utilize the uiaxes function, and try to plot it there, I get only a straight line. I've saved the maze in a 2D Matrix. I have 0 clue where my mistake is. Can someone help me out?
Below is the section of code that I'm using to plot the maze.
displayMaze(displayMaze == 1) = NaN;
maze_show = uiaxes;
maze_show.Position = [30 36 326 250];
maze_show.XLim=[0 2*rows+2];
maze_show.YLim=[0 2*cols+2];
for count = 1: length(displayMaze);
temp = displayMaze(count,:);
temp(~isnan(temp)) = count;
displayMaze(count,:) = temp;
plot( maze_show,displayMaze(count,:),'k','linewidth',2.5)
hold on
end
for count =1: length(displayMaze)
plot(maze_show,count*ones((length(displayMaze)),1),displayMaze(:,count),'k','linewidth',2.5)
hold on
end
  댓글 수: 1
Athrey Ranjith Krishnanunni
Athrey Ranjith Krishnanunni 2021년 1월 13일
hold on
uses gca and gcf to decide which axes to hold, but can't see UIAxes objects.
You should explicitly specify which axes to hold:
hold(maze_show,'on')

댓글을 달려면 로그인하십시오.

답변 (1개)

Akanksha Shrimal
Akanksha Shrimal 2022년 1월 27일
Hi,
While using “UIAxes” object for plotting, it is important to specify the “UIAxes” object as first argument for the hold functions. The following changes to the code will resolve your issue:
Replace
hold on
With
hold(maze_show,'on')
Please refer to “UIAxesdocumentation for more information.
Hope this helps.

카테고리

Help CenterFile Exchange에서 Labyrinth problems에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by