Filter löschen
Filter löschen

Display default value in the edit box in MATLAB GUI

27 Ansichten (letzte 30 Tage)
Pankaja Tanjore
Pankaja Tanjore am 25 Jul. 2015
Bearbeitet: Shameer Parmar am 14 Jun. 2016
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

Antworten (2)

Walter Roberson
Walter Roberson am 25 Jul. 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 Kommentare
Evan Bates
Evan Bates am 30 Apr. 2016
where do you put the initialization?
Walter Roberson
Walter Roberson am 30 Apr. 2016
You could put it in the Create function for edit_box1

Melden Sie sich an, um zu kommentieren.


Shameer Parmar
Shameer Parmar am 14 Jun. 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

Kategorien

Mehr zu Migrate GUIDE Apps finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by