How do I use the rectangle function in a GUI axes using AppDesigner?

I am trying to include this function in my GUI on AppDesigner, but it keeps drawing an error message.
function GUIshipPlacement()
for i = 0:3
for j = 0:3
rectangle(app.UIAxes,'Position', [i, j, 1, 1], 'FaceColor', [0 0.4470 0.7410], ...
'EdgeColor', 'k');
rectangle(app.UIAxes,'Position', [i+0.375, j+0.375, 0.25, 0.25], ...
'Curvature', [1, 1], 'FaceColor', [1, 1, 1], 'EdgeColor', [0, 0, 1]);
end
end
Error Msg:
Unable to resolve the name app.UIAxes.
Error in GUIshipPlacement (line 13) rectangle(app.UIAxes,'Position', [i, j, 1, 1], 'FaceColor', [0 0.4470 0.7410], ...

回答 (1 件)

Adam Danz
Adam Danz 2021 年 5 月 10 日
編集済み: Adam Danz 2021 年 5 月 10 日

0 投票

To specify the parent handle, use the parent name-value pair, but the syntax you used should have also worked.
rectangle('Position', [i, j, 1, 1], 'FaceColor', [0 0.4470 0.7410], ...
'EdgeColor', 'k','Parent',app.UIAxes)
or
rectangle(app.UIAxes,'Position', [i, j, 1, 1], 'FaceColor', [0 0.4470 0.7410], ...
'EdgeColor', 'k') 'EdgeColor', 'k')
This leads me to believe that you're using a non-existant handle to your UIAxes.

3 件のコメント

Francis Silvestri
Francis Silvestri 2021 年 5 月 10 日
Thankyou for the response.
The GUI is still showing this error after the code is run:
Unable to resolve the name app.UIAxes.
Error in GUIshipPlacement (line 14)
'EdgeColor', 'k','Parent',app.UIAxes);
Adam Danz
Adam Danz 2021 年 5 月 10 日
編集済み: Adam Danz 2021 年 5 月 12 日
I just modified my answer because I realized the syntax you used should have also worked. The problem is probably that you're using a handle that doesn't exist.
Is this "app.UIAxes" your actual axes handle?
Lateef Adewale Kareem
Lateef Adewale Kareem 2025 年 9 月 15 日
it is either you didnt send in the app into the function. or you didnt add axis to the UI components.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange で Develop Apps Using App Designer についてさらに検索

製品

リリース

R2021a

質問済み:

2021 年 5 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by