Display default value in the edit box in MATLAB GUI

10 visualizzazioni (ultimi 30 giorni)
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

Risposte (2)

Walter Roberson
Walter Roberson il 25 Lug 2015
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 Commenti
Evan Bates
Evan Bates il 30 Apr 2016
where do you put the initialization?
Walter Roberson
Walter Roberson il 30 Apr 2016
You could put it in the Create function for edit_box1

Accedi per commentare.


Shameer Parmar
Shameer Parmar il 14 Giu 2016
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

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by