Problem on GUIDE Initialization Value

조회 수: 1 (최근 30일)
Baris Ciftci
Baris Ciftci 2018년 3월 23일
댓글: Baris Ciftci 2018년 3월 27일
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에서 Startup and Shutdown에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by