Estoy realizando mi tesis de fin de grado, mi problema es que tengo que capturar datos con un pic y mandarlos por usb a la pc (esto funciona), luego quiero graficar los datos que recibo en una gui pero grafica al final de la adquision de los datos.
Aca cito el codigo:
function varargout = prueba_gui(varargin)
% PRUEBA_GUI M-file for prueba_gui.fig
% PRUEBA_GUI, by itself, creates a new PRUEBA_GUI or raises the existing
% singleton*.
%
% H = PRUEBA_GUI returns the handle to a new PRUEBA_GUI or the handle to
% the existing singleton*.
%
% PRUEBA_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PRUEBA_GUI.M with the given input arguments.
%
% PRUEBA_GUI('Property','Value',...) creates a new PRUEBA_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before prueba_gui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to prueba_gui_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help prueba_gui
% Last Modified by GUIDE v2.5 01-Dec-2010 18:20:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @prueba_gui_OpeningFcn, ...
'gui_OutputFcn', @prueba_gui_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before prueba_gui is made visible.
function prueba_gui_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 prueba_gui (see VARARGIN)
% Choose default command line output for prueba_gui
handles.output = hObject;
%%%%------------------------------------------------------
sw=get(handles.togglebutton1,'Value');
handles.sw=sw;
disp(sw)
plot(rand(1,10),'r');
%%%%%------------------------------------------------------
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes prueba_gui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = prueba_gui_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function grafica_CreateFcn(hObject, eventdata, handles)
% hObject handle to grafica (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate grafica
% --- Executes during object deletion, before destroying properties.
function grafica_DeleteFcn(hObject, eventdata, handles)
% hObject handle to grafica (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% axes(handles.grafica);
sw=get(handles.togglebutton1,'Value');
handles.sw=sw;
disp(sw)
axes(handles.grafica)
presion=[0];
flujo=[0];
conc_ox=[0];
if handles.sw
PS=serial('COM4');
set(PS,'Baudrate',19200); % se configura la velocidad a 9600 Baudios
set(PS,'StopBits',1); % se configura bit de parada a uno
set(PS,'DataBits',8); % se configura que el dato es de 8 bits, debe estar entre 5 y 8
set(PS,'Parity','none'); % se configura sin paridad
% PS.InputBufferSize = 600;
fopen(PS);
i=0;
limite=2000;
% j=0;
% while j<5
disp(handles.sw)
while i<limite
p=str2double(fscanf(PS));
f=str2double(fscanf(PS));
co=str2double(fscanf(PS));
flujo=[flujo;f];
presion=[presion;p];
conc_ox=[conc_ox;co];
i=i+1;
% t=[t;(i*0.005)];
% sw=get(handles.togglebutton1,'Value');
% handles.sw=sw;
hold on
plot(flujo)
plot(presion,'r')
plot(conc_ox,'g')
hold off
if i==(limite)
fclose(PS);
delete(PS);
clear PS;
end
end
end
guidata(hObject,handles)
% Hint: get(hObject,'Value') returns toggle state of togglebutton1
% --- Executes during object deletion, before destroying properties.
function togglebutton1_DeleteFcn(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% disp('salto el ciclo')
% fclose(PS);
% delete(PS);
% clear PS;
% hold on
% plot(flujo)
% plot(presion,'r')
% plot(conc_ox,'g')
% hold off