Display default value in the edit box in MATLAB GUI

30 ビュー (過去 30 日間)
Pankaja Tanjore
Pankaja Tanjore 2015 年 7 月 25 日
編集済み: Shameer Parmar 2016 年 6 月 14 日
Hello,
I have a MATLAB GUI which contains the edit box.The value to this edit box is entered by the user . If the value is not entered by the user the default value has to be displayed or the previously set value has to be displayed in the edit box. Let me know how to set the default value to the edit box and display it if no value is entered , also how to store the value that is set . Previously set value has to be accessed and displayed if new value is not entered by the user.
It would be grateful if you let me know how this is done.
Looking forward to hear from you at the earliest.
Thanks
Pankaja

回答 (2 件)

Walter Roberson
Walter Roberson 2015 年 7 月 25 日
Initialization
handles.prev_value = TheDefaultValue;
set(handles.edit_box1, 'String', handles.prev_value);
and callback
function edit_box1_callback(hObject, event, handles)
new_value = strtrim(get(hObject, 'String'));
if isempty(new_value)
new_value = handles.prev_value;
end
set(hObject, 'String', new_value);
handles.prev_value = new_value;
guidata(hObject, handles);
end
  2 件のコメント
Evan Bates
Evan Bates 2016 年 4 月 30 日
where do you put the initialization?
Walter Roberson
Walter Roberson 2016 年 4 月 30 日
You could put it in the Create function for edit_box1

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


Shameer Parmar
Shameer Parmar 2016 年 6 月 14 日
Hello Pankaja,
You can do this, by creating new function in your code file (i.e. in .m file of your GUI).
1. Simply create new function at the end of your actual code as shown below:
function default(hObject, handles)
set(handles.edit1, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.edit2, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.edit3, 'string', 'WhateverYouWant_But_InStringFormat');
.
.
.
set(handles.edit100, 'string', 'WhateverYouWant_But_InStringFormat');
guidata(hObject, handles);
end
2. Call this function in the Opening function of your GUI as follows:
function xxxxxx_OpeningFcn(hObject, eventdata, handles, varargin)
% lines of code
.
.
default(hObject, handles);
.
.
guidata(hObject, handles);
end
You can call function "default()" wherever you want, in callback of any button/field of your GUI to make the text value default, as per your requirement.
Try for this and let me know if you face any issue

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by