Hot to change the settings of multiple gui components at the same time

Hello,
I have a programmatically written gui. Their units are in pixels. After writing everything in pixels, I wanted to set all the units to normalized. I don't want to do it one by one. Do you know how I can set to normalized for multiple handles at the same time?
Thank you,
Emre

 採用された回答

Sean de Wolski
Sean de Wolski 2012 年 8 月 10 日

0 投票

Okay:
handles = struct('h1',pi,'h2',3,'edit1',17); %exmaple handles
set(cell2mat(struct2cell(handles)),'somefield',some_value);

3 件のコメント

Seyhan Emre Gorucu
Seyhan Emre Gorucu 2012 年 8 月 10 日
編集済み: Seyhan Emre Gorucu 2012 年 8 月 10 日
Hello,
Can you help me with this error?
clc
clear
a=figure;
position=get(a,'position');
dx=position(3);
dy=position(4);
handles.text=uicontrol(a,'style','text',...
'units','pixels',...
'string','anayin',...
'position',[dx/2 dy/2 100 40],...
'fontsize',8);
guidata(handles.text,handles)
tobenormalized=struct('handles.text',handles.text);
set(cell2mat(struct2cell(tobenormalized)),'units',normalized);
Sean de Wolski
Sean de Wolski 2012 年 8 月 10 日
You can't have the '.' in the field name of a struct. It looks lik eyou probably want:
tobenormalized=struct('text',handles.text);
Seyhan Emre Gorucu
Seyhan Emre Gorucu 2012 年 8 月 10 日
thanks

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

その他の回答 (2 件)

Matt Fig
Matt Fig 2012 年 8 月 10 日

3 投票

Pass in a vector of the handles:
u(1) = uicontrol;
u(2) = uicontrol;
u(3) = uicontrol;
set(u,'units','norm')

5 件のコメント

Seyhan Emre Gorucu
Seyhan Emre Gorucu 2012 年 8 月 10 日
Thank you for the answer. I already names my handles. Some of them are in vector form as you show, some of them aren't. I guess at this point I have to do them one by one. I wish there was something like set(all,'units','normalized')...
Matt Fig
Matt Fig 2012 年 8 月 10 日
In that case, something like this would be easiest of all!
set(findall(gcf,'units','pix'),'units','norm')
Seyhan Emre Gorucu
Seyhan Emre Gorucu 2012 年 8 月 10 日
thanks.
Addy
Addy 2018 年 5 月 9 日
In that case, something like this would be easiest of all!
set(findall(gcf,'units','pix'),'units','norm')
OMG. Thank you very much for this. I finally found this gold after 5 hours of madness :^)
Kevin Phung
Kevin Phung 2019 年 3 月 25 日
編集済み: Kevin Phung 2019 年 3 月 25 日
ditto that!! That's one beautiful line. Thanks @Loginatorist

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

カテゴリ

ヘルプ センター および File Exchange で Migrate GUIDE Apps についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by