How to change the property of a GUI button by a function?

2 ビュー (過去 30 日間)
Albert Bing
Albert Bing 2019 年 12 月 25 日
コメント済み: Albert Bing 2019 年 12 月 26 日
I am writing a GUI function. Some uicontrols need to switch their position in certain cases. So I wrote a nested function, to switch their positions if needed.
But it turned out, that their positions were only switched in the nest function. Outside the nested function, they kept their previous positions.
So how to change the UI's properties by functions?
To make it simple, my functions were as following.
function main_func()
h = figure();
b1 = uicontrol(h, 'some properties', 'Position', p1);
b2 = uicontrol(h, 'some properties', 'Position', p2);
switchPosition();
function switchPosition()
set(b1, 'Position', p2);
set(b2, 'Position', p1);
end
end
I also tried function with b1 and b2 as the input variables, but it didn't work either.

採用された回答

Image Analyst
Image Analyst 2019 年 12 月 25 日
Try this
function switchPosition(b1, b2)
pos1 = b1.Position;
pos2 = b2.Position;
b1.Position = pos2;
b2.Position = pos1;
end
  1 件のコメント
Albert Bing
Albert Bing 2019 年 12 月 26 日
Thanks.
I know what I was doing wrong.
The function I wrote was actually right, but I used it in a wrong way. So they were switched, and switched back.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by