Stop button (GUI)
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I have this code below(except for a few beginning lines) and I have problems because I want the measurement to stop when I click on the Stop button, but it doesn't work. Any idea of the problem?
% --- Executes just before Medida_Serial_hcsr04 is made visible.
function Medida_Serial_hcsr04_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 command line arguments to Medida_Serial_hcsr04 (see VARARGIN)
% Choose default command line output for Medida_Serial_hcsr04
handles.output = hObject;
set(handles.guardar,'Enable','off');
handles.stop=false;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Medida_Serial_hcsr04 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Medida_Serial_hcsr04_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
% --- Executes on button press in Medir.
function Medir_Callback(hObject, eventdata, handles)
% hObject handle to Medir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.Abrir,'Enable','off');
%handles.stop=0;
cla reset; %Limpiar la grafica cada vez que se hace click
s = abrir_puerto();
handles.x=1:100;
handles.h=animatedline('Marker','o','LineWidth',1,'Color','b');
xlabel('Number of samples');
ylabel('Distance (cm)');
i=0; %Hay que recoger aqui el valor del que le pasa el stop button
while handles.stop==false
handles.distancia(i)=fscanf(s,'%d');
addpoints(handles.h,i,handles.distancia(i));
drawnow;
i=i+1;
end
set(handles.guardar,'Enable','on');
set(handles.Abrir,'Enable','on');
guidata(hObject,handles);
cerrrar_puerto(s);
% --- Executes on button press in guardar.
function guardar_Callback(hObject, eventdata, handles)
% hObject handle to guardar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
dist = handles.distancia;
guardar_archivo(dist);
% --- Executes on button press in Abrir.
function Abrir_Callback(hObject, eventdata, handles)
% hObject handle to Abrir (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Abrir_fichero();
% --- Executes on button press in stop.
function stop_Callback(hObject, eventdata, handles)
% hObject handle to stop (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of stop
handles.stop=true;
guidata(hObject,handles);
Thank you
0 comentarios
Respuestas (2)
Jan
el 28 de Feb. de 2017
Editada: Jan
el 28 de Feb. de 2017
You use the value of the handles struct, but do not update the struct:
while handles.stop==false
distancia(i)=fscanf(s,'%d');
addpoints(handles.h,i, distancia(i));
drawnow;
i=i+1;
handles = guidata(hObject); % <- get the current value
end
handles.distancia = distancia; % <- to avoid overwriting by GUIDATA
2 comentarios
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!