How can i generate a graph dynamic
3 views (last 30 days)
Show older comments
Hello community, I'm trying to generate a graph of the ECG trace on GUI, but it shall retain the data for 24h.how 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
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?
Answers (4)
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])
end
fclose(fid)
%%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));
figure,plot(Data(Range,2),Data(Range,1))
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.
3 Comments
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
figure,plot(Data(:,2),Data(:,1))
datetick('x',16),axis tight
newLim = get(gca,'XLim');
newx = Data(:,2);
ax = axis %current axis limits
axis(axis)
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', ...
'Rotation',45);
set(gca,'XtickLabel','')
for i = 1:length(t)
ext(i,:) = get(t(i),'Extent');
end
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', ...
'HorizontalAlignment','center');
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!