GUI Code with a written Code for axes and slider

1 view (last 30 days)
function varargout = Signal(varargin)
% SIGNAL MATLAB code for Signal.fig
% SIGNAL, by itself, creates a new SIGNAL or raises the existing
% singleton*.
%
% H = SIGNAL returns the handle to a new SIGNAL or the handle to
% the existing singleton*.
%
% SIGNAL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIGNAL.M with the given input arguments.
%
% SIGNAL('Property','Value',...) creates a new SIGNAL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Signal_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Signal_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 Signal
% Last Modified by GUIDE v2.5 20-Feb-2019 13:38:50
% Begin initialization code - DO NOT EDIT
%generate some data and set the x window size
load ('100m.mat')
y = (val - 1024 )/200;
Fs = 360;
x = (0:length(y)-1)/Fs ;
xwindow_size=1;
xwindow_min=min(x);
xwindow_max=max(x);
%make the GUI
h=struct;
h.f=figure(1);
clf(h.f)%make sure the figure is empty, not needed if you use h.f=figure;
h.xwindow_size=xwindow_size;
h.xwindow_min=xwindow_min;
h.xwindow_max=xwindow_max;
h.ax=axes('Parent',h.f,...
'Units','Normalized',...
'Position',[0.1 0.3 0.8 0.6]);
h.slider=uicontrol('Parent',h.f,...
'Style','slider',...
'Value',h.xwindow_min+h.xwindow_size/2,...
'min',h.xwindow_min+h.xwindow_size/2,...
'max',h.xwindow_max-h.xwindow_size/2,...
'Units','Normalized',...
'Position',[0.1 0.1 0.8 0.1],...
'Callback',@sliderCallback);
guidata(h.f,h)
%make the plot
plot(x,y,'Parent',h.ax)%create the plot itself
%set(h.ax,'YLim',[min(y) max(y)])%fix the y-axis to specific values
set(h.ax,'YLim',[floor(min(y)) ceil(max(y))])%fix the y-axis to specific values
sliderCallback(h.f)%initialize the x-axis
function sliderCallback(obj,evnt)
handles=guidata(obj);
a=get(handles.slider,'Value');
set(handles.ax,'XLim',[-0.5 0.5]*handles.xwindow_size+a)
end
function varargout = Signal(varargin)
% SIGNAL MATLAB code for Signal.fig
% SIGNAL, by itself, creates a new SIGNAL or raises the existing
% singleton*.
%
% H = SIGNAL returns the handle to a new SIGNAL or the handle to
% the existing singleton*.
%
% SIGNAL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SIGNAL.M with the given input arguments.
%
% SIGNAL('Property','Value',...) creates a new SIGNAL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Signal_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Signal_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 Signal
% Last Modified by GUIDE v2.5 20-Feb-2019 13:38:50
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Signal_OpeningFcn, ...
'gui_OutputFcn', @Signal_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 Signal is made visible.
function Signal_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 Signal (see VARARGIN)
% Choose default command line output for Signal
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Signal wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Signal_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 Insert.
function Insert_Callback(hObject, eventdata, handles)
clc;
load ('100m.mat')
ECGsignal = (val - 1024 )/200;
Fs = 360;
t = (0:length(ECGsignal)-1)/Fs ;
plot (t,ECGsignal)
% --- Executes on button press in Clear.
function Clear_Callback(hObject, eventdata, handles)
cla reset;
% --- Executes on button press in ZoomIn.
function ZoomIn_Callback(hObject, eventdata, handles)
zoom on
% --- Executes on button press in ZoomOff.
function ZoomOff_Callback(hObject, eventdata, handles)
zoom off
% --- Executes on button press in ResetZoom.
function ResetZoom_Callback(hObject, eventdata, handles)
zoom out
% --- Executes on button press in Pause.
function Pause_Callback(~, eventdata, handles)
% hObject handle to Pause (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if(strcmp(get(handles.Pause,'String'),'Pause'))
set(handles.Pause,'String','Play');
uiwait();
else
set(handles.Pause,'String','Pause');
uiresume();
end
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Signal_OpeningFcn, ...
'gui_OutputFcn', @Signal_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 Signal is made visible.
function Signal_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 Signal (see VARARGIN)
% Choose default command line output for Signal
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes Signal wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Signal_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 Insert.
function Insert_Callback(hObject, eventdata, handles)
clc;
load ('100m.mat')
ECGsignal = (val - 1024 )/200;
Fs = 360;
t = (0:length(ECGsignal)-1)/Fs ;
plot (t,ECGsignal)
% --- Executes on button press in Clear.
function Clear_Callback(hObject, eventdata, handles)
cla reset;
% --- Executes on button press in ZoomIn.
function ZoomIn_Callback(hObject, eventdata, handles)
zoom on
% --- Executes on button press in ZoomOff.
function ZoomOff_Callback(hObject, eventdata, handles)
zoom off
% --- Executes on button press in ResetZoom.
function ResetZoom_Callback(hObject, eventdata, handles)
zoom out
% --- Executes on button press in Pause.
function Pause_Callback(~, eventdata, handles)
% hObject handle to Pause (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if(strcmp(get(handles.Pause,'String'),'Pause'))
set(handles.Pause,'String','Play');
uiwait();
else
set(handles.Pause,'String','Pause');
uiresume();
end
How can i fit that code to display an ECG signal and Move with a slider along x-axis ?

Answers (0)

Categories

Find more on Data Exploration in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!