フィルターのクリア

Stop button (GUI)

6 ビュー (過去 30 日間)
Itziar Uzqueda
Itziar Uzqueda 2017 年 2 月 28 日
コメント済み: Itziar Uzqueda 2017 年 3 月 1 日
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

回答 (2 件)

Image Analyst
Image Analyst 2017 年 2 月 28 日
I have attached a demo for that.

Jan
Jan 2017 年 2 月 28 日
編集済み: Jan 2017 年 2 月 28 日
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 件のコメント
Itziar Uzqueda
Itziar Uzqueda 2017 年 3 月 1 日
it's not working. It looks as if it wasn't changing the value os handles.stop. It never stops
Itziar Uzqueda
Itziar Uzqueda 2017 年 3 月 1 日
Finally I have solved using global variables. Thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by