MATLAB: Can i set all text boxes to their default value by using only one command

matlab gui

I 'm using this command to set textbox to its default value I have 17 text boxes in my GUI. I want to reset all of them by using command only one time instead of calling this 17 times. Is it possible?
set(handles.text1, 'string', 'default');

Best Answer

Hello Mania,
You can achieve your requirement, 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.text1, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.text2, 'string', 'WhateverYouWant_But_InStringFormat');
set(handles.text3, 'string', 'WhateverYouWant_But_InStringFormat');
.
.
.
set(handles.text17, '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 function 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.