MATLAB: How to plot a continuous signal using guide

continuousguiguideinterfaceplotsignal

I am making a graph interface for a spectrum analyzer using guide. I want to plot the instrument signal power while pressing any button or making any changes, using of course guide. I want to know if there is a way to plot the signal without having to wait out the sampling in order to press another button (go to any callback).
[Merged information from duplicate question]
I am making a graph interface for a spectrum analyzer using guide. I want to plot the instrument signal power while pressing any button or making any changes, using of course guide. I want to know if there is a way to plot the signal without having to wait out the sampling in order to press another button (go to any callback).
this is my code:
function varargout = analizadorgui(varargin)
% ANALIZADORGUI M-file for analizadorgui.fig
% ANALIZADORGUI, by itself, creates a new ANALIZADORGUI or raises the existing
% singleton*.
%




% H = ANALIZADORGUI returns the handle to a new ANALIZADORGUI or the handle to
% the existing singleton*.
%
% ANALIZADORGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in ANALIZADORGUI.M with the given input arguments.
%
% ANALIZADORGUI('Property','Value',...) creates a new ANALIZADORGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before analizadorgui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to analizadorgui_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 analizadorgui
% Last Modified by GUIDE v2.5 10-May-2012 15:52:12
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @analizadorgui_OpeningFcn, ...
'gui_OutputFcn', @analizadorgui_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 analizadorgui is made visible.
function analizadorgui_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 analizadorgui (see VARARGIN)
% Choose default command line output for analizadorgui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes analizadorgui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = analizadorgui_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 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
handles.varobj1=obj1;
% 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);
% Set the data trace format to REAL, 32 bits
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 on
% Plot cycle
for i=1:100
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
end
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 edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.






function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called






% Hint: edit controls usually have a white background on Windows.



% See ISPC and COMPUTER.



if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
cna=get(handles.edit1,'String');
cnb=str2double(cna);
cn=num2str(cnb);
center=[':FREQuency:CENTer ',cn];
set(handles.text2,'String',cn);
fprintf(obj1,center);
% hObject handle to pushbutton1 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
sta=get(handles.edit2,'String');
stb=str2double(sta);
st=num2str(stb);
start=[':FREQuency:STARt ',st];
fprintf(obj1,start);
set(handles.text3,'String',st);
% hObject handle to pushbutton2 (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 pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
spa=get(handles.edit3,'String');
spb=str2double(spa);
sp=num2str(spb);
stop=[':FREQuency:STOP ',sp];
fprintf(obj1,stop);
set(handles.text4,'String',sp);
% hObject handle to pushbutton3 (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 pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
fclose(obj1);
delete(obj1);
clear obj1;
set(handles.text1,'String',' Close ');
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function text1_CreateFcn(hObject, eventdata, handles)
% hObject handle to text1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
%frecuencia=query(obj1,':FREQuency:STARt?');


fprintf(obj1,':DISPlay:MENU:STATe 1');
frecuencia=query(obj1,':CALCulate:MARKer1:Y?');
set(handles.text5,'String',frecuencia);
% hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function edit6_Callback(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit6 as text
% str2double(get(hObject,'String')) returns contents of edit6 as a double
% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
aa=get(handles.edit6,'String');
ab=str2double(aa);
at=num2str(ab);
atten=[':SOURce:POWer:ATTenuation ',at];
fprintf(obj1,atten);
set(handles.text6,'String',at);
% hObject handle to pushbutton7 (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 pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
%frecuencia=query(obj1,':FREQuency:STARt?');
fprintf(obj1,':CALCulate:MARKer1:MAXimum:LEFT');
% hObject handle to pushbutton8 (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 pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
obj1=handles.varobj1;
%frecuencia=query(obj1,':FREQuency:STARt?');
fprintf(obj1,':CALCulate:MARKer1:MAXimum:RIGHt');
% hObject handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function text2_CreateFcn(hObject, eventdata, handles)
% hObject handle to text2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (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 axes1
this is the inferface:

Best Answer

GUIDE-based GUIs use the same technology as MATLAB as a whole. If it can be done in MATLAB, it can be done in GUIDE. (Though it might be a pain to work with the uglier parts of GUIDE...)
GUIDE does not itself offer any facilities to sample data: you will need to code one of the various mechanisms in MATLAB directly. Most of the mechanisms work asynchronously.
Related Question