How to move a rectangle when a button is pressed in app designer?
1 view (last 30 days)
Show older comments
I created a rectangle in the UIAxes window by using
tArea = rectangle(app.UIAxes, 'Position', [25 25 50 50], 'FaceColor', [0 1 .75 .3], 'EdgeColor', [0 1 .75 .3]);
but now I want to change its position when I click a button in the app. I wanted to just use
tArea.Position = [25 30 50 50];
but I think tArea is outside the scope of the buttonClicked function. I am not sure the best way to make tArea visible to the other function in app designer. Or is there a better way to do it altogether?
0 Comments
Accepted Answer
Ameer Hamza
on 8 May 2018
The easiest way is to create a public property in App designer. Go to Code View, in the top bar click the arrow under property and click Public Property. Name the property tArea and access it from any method using app.tArea. For example,
app.tArea = rectangle(app.UIAxes, 'Position', [25 25 50 50], 'FaceColor', [0 1 .75 .3], 'EdgeColor', [0 1 .75 .3]);
then to change
app.tArea.Position = [25 30 50 50];
0 Comments
More Answers (0)
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!