How can I display on a figure's title block data as the code is running? I was able to do it for time, but struggling to show BPM
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Carlos Nunez
am 16 Jun. 2018
Beantwortet: Walter Roberson
am 17 Jun. 2018
clear all;
a= arduino('COM3','Uno');
b=readVoltage(a,'A0');
x=2.4;
bc=1;
fs=30;
beat_count=0;
t=[];
tic;
for k=1:100;
toc<2;
b=readVoltage(a,'A0');
x=[x,b];
t=[t;toc];
hP1.XData=t;
plot(x,'ro-');
title(sprintf('t=%g[s],[BPM]= %g',t(end), c(end)));
xlabel('Samples');
ylabel('Electrical Activity');
grid on;
drawnow;
hold on;
for k=2:length(x)-1;
if( x(k)> x(k-1) & x(k)> x(k+1) & x(k)>1);
bc = (bc + 1 );
c = (bc*fs)/(60*length(x));
end
end
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 17 Jun. 2018
Generally speaking the line
title(sprintf('t=%g[s],[BPM]= %g',t(end), c(end)));
looks plausible. However, you have not initialized c at that point: you do not set c until the for/if sequence after that (and that sequence will not always assign a value to c either.) You are also expecting c to be an array when you use c(end), but you look like you are only assigning a scalar to it.
Note: it would look to make more sense to
plot(t, x)
Assigning t to hP1.XData does nothing because hP1 has not been defined or used elsewhere. If you are expecting that hP1 is the handle to a plot, then note that your plot(x,'ro-') would generate a new line rather than update an existing line. With the 'hold on" in effect, it looks like you are continually re-drawing over existing areas.
You should consider using animatedLine() instead of the way you are plotting now.
hP1 = animatedline();
for ...
...
addpoints(hP1, t, b);
drawnow update
...
end
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!