Clear Filters
Clear Filters

Right now, changing the spinner's value will create a new maze, but the mazes are still 10-by-10. Try running the app to verify this behavior. To fix this, you can use the gr

11 views (last 30 days)
n the callback function, get the spinner's value and call the amaze function with the spinner's value as an input.
% Properties that correspond to app components
properties (Access = public)
UIFigure matlab.ui.Figure
GridSizeSpinner matlab.ui.control.Spinner
GridSizeSpinnerLabel matlab.ui.control.Label
NewMazeButton matlab.ui.control.Button
UIAxes matlab.ui.control.UIAxes
end
% Callbacks that handle component events
methods (Access = private)
% Callback function: GridSizeSpinner, NewMazeButton
function NewMazeButtonPushed(app, event)
[wall,wx,wy] = amaze();
plot(app.UIAxes,wall,"XData",wx,"YData",wy,"NodeLabel",[])
axis(app.UIAxes,"equal")
end
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(app)
% Create UIFigure and hide until all components are created
app.UIFigure = uifigure('Visible', 'off');
app.UIFigure.Position = [100 100 321 254];
app.UIFigure.Name = 'MATLAB App';
% Create UIAxes
app.UIAxes = uiaxes(app.UIFigure);
title(app.UIAxes, 'Maze')
app.UIAxes.XTick = [];
app.UIAxes.XTickLabel = '';
app.UIAxes.YTick = [];
app.UIAxes.YTickLabel = '';
app.UIAxes.Box = 'on';
app.UIAxes.Position = [63 57 200 185];
% Create NewMazeButton
app.NewMazeButton = uibutton(app.UIFigure, 'push');
app.NewMazeButton.ButtonPushedFcn = createCallbackFcn(app, @NewMazeButtonPushed, true);
app.NewMazeButton.Position = [205 23 100 23];
app.NewMazeButton.Text = 'New Maze';
% Create GridSizeSpinnerLabel
app.GridSizeSpinnerLabel = uilabel(app.UIFigure);
app.GridSizeSpinnerLabel.HorizontalAlignment = 'right';
app.GridSizeSpinnerLabel.Position = [4 23 54 22];
app.GridSizeSpinnerLabel.Text = 'Grid Size';
% Create GridSizeSpinner
app.GridSizeSpinner = uispinner(app.UIFigure);
app.GridSizeSpinner.Step = 5;
app.GridSizeSpinner.Limits = [5 30];
app.GridSizeSpinner.ValueChangedFcn = createCallbackFcn(app, @NewMazeButtonPushed, true);
app.GridSizeSpinner.Position = [73 23 100 22];
app.GridSizeSpinner.Value = 5;
% Show the figure after all components are created
app.UIFigure.Visible = 'on';
end
end
% App creation and deletion
methods (Access = public)
% Construct app
function app = myapp
% Create UIFigure and components
createComponents(app)
% Register the app with App Designer
registerApp(app, app.UIFigure)
if nargout == 0
clear app
end
end
% Code that executes before app deletion
function delete(app)
% Delete UIFigure when app is deleted
delete(app.UIFigure)
end
end
end
  1 Comment
Steven Lord
Steven Lord 38 minutes ago
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the free MATLAB Onramp tutorial to quickly learn the essentials of MATLAB.
If you aren't sure where to start because you're not familiar with the mathematics you'll need to solve the problem, I recommend asking your professor and/or teaching assistant for help.

Sign in to comment.

Answers (1)

Voss
Voss 35 minutes ago
Edited: Voss 34 minutes ago
% Callback function: GridSizeSpinner, NewMazeButton
function NewMazeButtonPushed(app, event)
% get the spinner's value:
val = app.GridSizeSpinner.Value;
% call the amaze function with the spinner's value as an input:
[wall,wx,wy] = amaze(val);
plot(app.UIAxes,wall,"XData",wx,"YData",wy,"NodeLabel",[])
axis(app.UIAxes,"equal")
end

Community Treasure Hunt

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

Start Hunting!