How to move a rectangle when a button is pressed in app designer?

1 回表示 (過去 30 日間)
Kyle Millar
Kyle Millar 2018 年 5 月 7 日
回答済み: Ameer Hamza 2018 年 5 月 8 日
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?

採用された回答

Ameer Hamza
Ameer Hamza 2018 年 5 月 8 日
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 件)

カテゴリ

Help Center および File ExchangeDevelop 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