How to draw multiple rooms within MATLAB App Designer without overlapping?

2 次查看(过去 30 天)
Good day. I am trying to draw multiple rooms within app desinger on a ui axes with the following code:
function mainfloor(app)
rectangle(app.UIAxes, 'Position', [5,5,app.L,app.W]);
end.
This allows the user to enter the app.L value and the app.W to get the diemensions of the box. The problem i am getting is that the boxes are overlapping each other as seen in the image below:
Essientially I would like the boxes to be side by side as show in the image below:
Addtionally, I would like app desinger to recongise each room as a separate entitiy when the user enters each room dimension. I am fairly new to MATLab Appdesigner and any help would be apprecidated.

回答(1 个)

Gowtham
Gowtham 2023-9-12
编辑:Gowtham 2023-9-27
Hello Kyle,
I understand that you want to draw the rooms (rectangles) in app designer such that none of them overlap. To achieve this, we must provide information like length, width, and position of the room to the rectangle function which you have used.
Additionally, to access the room when the user enters it, we can store the references to these rooms in an app property rooms which is an array. Each of them can be accessed using the index number equal to the order in which they are created.
For a sample demonstration of this process, kindly refer to the following steps:
  • The Create Room button uses a callback to create the room with the desired properties given as input.
  • The Highlight Room button uses a callback to change the edge colour of a room using its index.
properties (Access = public)
rooms = [] % Description
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: CreateRoomButton
function CreateRoomButtonPushed(app, event)
room = rectangle(app.UIAxes, 'Position', [app.X_posEditField.Value, app.Y_posEditField.Value, ...
app.LengthEditField.Value, app.WidthEditField.Value]);
app.rooms = [app.rooms room];
end
% Button pushed function: HighlightRoomButton
function HighlightRoomButtonPushed(app, event)
room = app.rooms(app.RoomNumberEditField.Value);
room.EdgeColor = 'red';
end
end
Feel free to refer to the following documentation for further understanding:
  1. https://www.mathworks.com/help/matlab/ref/rectangle.html#d124e1340302
  2. https://www.mathworks.com/help/matlab/learn_matlab/matrices-and-arrays.html
  3. https://www.mathworks.com/help/matlab/creating_guis/write-callbacks-for-gui-in-app-designer.html
Hope it helps!
Regards,
Gowtham

类别

Help CenterFile Exchange 中查找有关 Develop Apps Using App Designer 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by