Setting up multiple EDIT TEXT boxes in gui by a single command

13 ビュー (過去 30 日間)
Ameer Hamza
Ameer Hamza 2018 年 1 月 31 日
コメント済み: Jan 2018 年 1 月 31 日
Is there any "single command" to set multiple edit text boxes in matlab gui for example, we use four lines for setting four edit text z=44; 1. set(handles.edit1,'string',z); %pasting value of z to all edit texts 2. set(handles.edit2,'string',z); 3. set(handles.edit3,'string',z); 4. set(handles.edit4,'string',z);
but i need a single lined command to do the same to compact my code. the idea about new code is
set(handles.edit1,handles.edit2,handles.edit3,handles.edit4,'string',z);

採用された回答

Jan
Jan 2018 年 1 月 31 日
編集済み: Jan 2018 年 1 月 31 日
set([handles.edit1,handles.edit2,handles.edit3,handles.edit4], 'string', z);
See: doc set in the first paragraph:
set(H,Name,Value) [...] If H is a vector of objects, then set
sets the property for all the objects.
So all you need is to provide the handles as a vector of objects.
  2 件のコメント
Ameer Hamza
Ameer Hamza 2018 年 1 月 31 日
編集済み: Ameer Hamza 2018 年 1 月 31 日
Thanks alot. actually i had to set 100 edit text values to 'z'. It worked for me.
Jan
Jan 2018 年 1 月 31 日
In a similar situation I define the handles.edit as a vector directly instead of using indices hidden in the fieldnames edit1, edit2, .... This is easy, if you do not work with GUIDE or if you create the edit fields dynamically in the CreateFcn. Then the code is much simpler:
set(handles.edit, 'string', z);

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by