How can i generate a graph dynamic
조회 수: 10 (최근 30일)
이전 댓글 표시
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
Joseph Cheng
2014년 9월 3일
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?
답변 (4개)
Joseph Cheng
2014년 9월 3일
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
Joseph Cheng
2014년 9월 4일
so what portion of my answer could you not have grabbed the necessary portions to get what you need?
the portions of the code you could have extracted from my example to do this are:
- Data = dlmread('loaded file path+name chosen by the push button')
- start acquisition is obviously row 1.
- end acquisition is obviously row(end).
- using date/time is shown in my use of datetick()
- plot data using plot() like i did before. if you wanted the full data file i wouldn't call that dynamic it would be more like automatically. dynamic would mean that it would be able to changed based on something else (ie my edit boxes that chose the start and stop time).
or are you struggling with even the concept of how to pull in the file, and create the plot? From the figures i assumed you were able to pull in the file as you had a button, had the file path+name shown, and the start and stop times.
What are you missing that i have not already given you?
Joseph Cheng
2014년 9월 12일
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');
참고 항목
카테고리
Help Center 및 File Exchange에서 Annotations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!