Clear Filters
Clear Filters

Problem on GUIDE Initialization Value

2 views (last 30 days)
Baris Ciftci
Baris Ciftci on 23 Mar 2018
Commented: Baris Ciftci on 27 Mar 2018
Hello,
When I run a GUI, I cannot set the initial value of a variable -handles.data- as 0. Here I copy related parts of my GUI .m file. The first part is the opening function and I try to initialize handles.data as '0000'. The second part is related to a push button, named On. When I run the GUI and press directly the On button afterwards, I expect the handles.data to be '0000', but it turns out to be the last saved value of itself in the previous run of the GUI.
Do you have any ideas to solve? Thanks in advance.
Baris
function test_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin unrecognized PropertyName/PropertyValue pairs from the
% command line (see VARARGIN)
% Choose default command line output for Test
handles.output = hObject;
set(handles.Off, 'Enable', 'off');
set(handles.pushbutton3, 'Enable', 'off');
set(handles.slider1,'Value', 0);
set(handles.uibuttongroup1,'selectedobject',handles.radiobutton1)
set(handles.text4,'String', '0.00')
handles.data='0000';
t=tcpip('192.168.1.10',7);
fopen(t);
handles.ipdata = t;
% create the listener for the slider
handles.sliderListener = addlistener(handles.slider1,'ContinuousValueChange', ...
@(hFigure,eventdata) slider1ContValCallback(...
hObject,eventdata));
% Update handles structure
guidata(hObject, handles);
function On_Callback(hObject, eventdata, handles)
% hObject handle to On (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
t = handles.ipdata;
handles.data=num2str(getappdata(0,'dutymax')*getappdata(0,'slider_Value'),'%04.f');
disp(handles.data);
guidata(hObject,handles)
fprintf(t, handles.data);
set(handles.Off, 'Enable', 'on');
set(handles.On, 'Enable', 'off');
set(handles.pushbutton3, 'Enable', 'on');
set(handles.radiobutton1, 'Enable', 'off');
set(handles.radiobutton2, 'Enable', 'off');

Answers (1)

Murali Krishna
Murali Krishna on 24 Mar 2018
Hello.. Try using clear all at the start of the code.
  1 Comment
Baris Ciftci
Baris Ciftci on 27 Mar 2018
Hi, Thanks for the answer. However, if I use clear all before the initialization function (starting with varargout...), it gives error. If I use at the end of initialization function, it runs but it does not help.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!