Hi I'm using GUI for do a spectrum analyzer interface. My problem is when I create a timer and call my function, appears a warning, something like that:
"the "handles" estructure is no defined or recognized"
thi is a part of my code:
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)obj1 = instrfind('Type', 'gpib', 'BoardIndex', 0, 'PrimaryAddress', 18, 'Tag', '');if isempty(obj1) obj1 = gpib('ni', 0, 18);else fclose(obj1); delete(obj1); clear obj1; obj1 = gpib('ni', 0, 18);end% Configure instrument object, obj1.
set(obj1, 'InputBufferSize', 10000);set(obj1, 'OutputBufferSize', 10000);% Connect to instrument object, obj1.
set(obj1,'Timeout',5);fopen(obj1);Nombre = query(obj1, '*IDN?');set(handles.text1,'String',Nombre);fprintf(obj1,':FORM:BORD SWAP');fprintf(obj1,':FORM:DATA REAL,32');% Get the nr of trace points
nr_points = str2double(query(obj1,':SWE:POIN?'));% Get the reference level
ref_lev = str2num(query(obj1,':DISP:WIND:TRAC:Y:RLEV?'));% Put the instrument in continuos mode
fprintf(obj1,':INIT:CONT ON');% Create and bring to front fi gure number 1
%figure(1)
% Create a plot handle, ph, and draw a line at the refl evel
handles.axes1=(1:nr_points);ph = plot(handles.axes1,ref_lev*ones(1,nr_points));% Adjust the x limits to the nr of points
% and the y limits for 100 dB of dynamic range
xlim([1 nr_points])ylim([ref_lev-100 ref_lev])% Activate the grid
grid ont =timer('timerfcn',@graficar,'Period',0.1); //THIS IS MY TIMERhandles.varobj1=obj1;handles.varph=ph;start(t);guidata(hObject,handles);% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function graficar(hObject, eventdata, handles) //THIS IS MYFUNCTION obj1=handles.varobj1; //THE WARNING REFERS TO THIS ph=handles.varph; //LINE OF CODE fprintf(obj1,':TRAC? TRACE1'); data = binblockread(obj1,'float32'); fscanf(obj1); %removes the terminator character
% Change the plot line data (fast update method)
set(ph,'Ydata',data); % fl ushes the plot event queue
drawnow guidata(hObject,handles);
Best Answer