Problem on GUIDE Initialization Value
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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');
0 Kommentare
Antworten (1)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!