How can i generate a graph dynamic

3 views (last 30 days)
Biza Ferreira
Biza Ferreira on 3 Sep 2014
Commented: Joseph Cheng on 12 Sep 2014
Hello community, I'm trying to generate a graph of the ECG trace on GUI, but it shall retain the data for can I make a dynamic chart. Wherein the x-axis, can allot time from the start of acquisition to the end. And on the y axis can generate the voltage?
  1 Comment
Joseph Cheng
Joseph Cheng on 3 Sep 2014
One of the initial things that would help is how are you getting the ECG data? is it going to come in real time with other parallel processes that needs to be done?

Sign in to comment.

Answers (4)

Biza Ferreira
Biza Ferreira on 3 Sep 2014
Edited: Biza Ferreira on 3 Sep 2014
First of all, thanks for replying Joseph Cheng, ECG data are obtained through a txt file. These data come in the form of ASCII, and are stored on a memory card in a txt file through this program after the file is opened and the data is read ...

Joseph Cheng
Joseph Cheng on 3 Sep 2014
So i'm assuming from the screen shot you already have something that pulls in and reads in the data. So here is a quick example:
%%generate sample file.
fid = fopen('sampleECG.txt','w');
dateN = datenum('03-Sep-2014 15:26:10','yyyymmddTHHMMSS');
for ind = 1:2:24*60 %sample every 2 min.
data= 2000+5*sin(2*pi*.009*ind);
dateN = addtodate(dateN,2,'minute');
Dvect = datevec(dateN);
fprintf(fid,'%02.0f %02d %02d %02d %02d %02d %02.0f\r\n',[data Dvect])
%%read in data
Data = dlmread('sampleECG.txt',' ');
Data = [Data(:,1) datenum(Data(:,2:end))];
%%find section of data you want to plot
%generate this by using edit fields
PlotRange = [2014 09 03 23 59 20;2014 09 04 15 01 20];
%convert the user entries into date numbers.
PlotRange = datenum(PlotRange);
%find the time in the files between the two ranges
Range = find(Data(:,2)>=PlotRange(1) & Data(:,2)<=PlotRange(2));
datetick('x',16),axis tight
So the first section I generate some sample data and then i read it in using dlmread() and store it in as data. to actually plot it dynamically would be that you would need to create a few edit boxes such that the user can enter the time window. here i just put it in as an already made array called PlotRange but this can simple be constructed from entries into the GUI. Then with the knowledge of the window of time we can then search the the dates for data we have. then plot.
Joseph Cheng
Joseph Cheng on 12 Sep 2014
you should stop entering comments to new "answers" as your replies are not answers. I am not going to code up a full gui but here are some snippits of code that should help you.
%%read in data
Data = dlmread('sampleECG.txt',' ');
Data = [Data(:,1) datenum(Data(:,2:end))];
startAqc = datestr(Data(1,2:end),31);
stopAqc = datestr(Data(end,2:end),31);
%%get and plot all data
datetick('x',16),axis tight
newLim = get(gca,'XLim');
newx = Data(:,2);
ax = axis %current axis limits
set(gca,'XTick', newx);
dateticks = datestr(newx,13);
yl = ax(3:4);
t = text(newx,yl(1)*ones(1,length(newx)),dateticks);
set(t,'HorizontalAlignment','right','VerticalAlignment','top', ...
for i = 1:length(t)
ext(i,:) = get(t(i),'Extent');
LowYPoint = min(ext(:,2));
% Place the axis label at this point
XMidPoint = Xl(1)+abs(diff(Xl))/2;
tl = text(XMidPoint,LowYPoint,'X-Axis Label', ...
'VerticalAlignment','top', ...

Sign in to comment.

Biza Ferreira
Biza Ferreira on 4 Sep 2014
Joseph Cheng, thanks for your reply, I think I do not explained myself well, soo when in my interface I release my "Open File" button all data come to interface,graph is automatically generated through the samples contained in txt file. I want to create something like this:

Biza Ferreira
Biza Ferreira on 12 Sep 2014
Joseph excuse my ignorance, is that you can send me an example, I have walked around it and can not do

Community Treasure Hunt

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

Start Hunting!