Problem on GUIDE Initialization Value

2 次查看(过去 30 天)
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');

回答(1 个)

Murali Krishna
Murali Krishna 2018-3-24
Hello.. Try using clear all at the start of the code.
  1 个评论
Baris Ciftci
Baris Ciftci 2018-3-27
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by