フィルターのクリア

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 回表示 (過去 30 日間)
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

採用された回答

Walter Roberson
Walter Roberson 2018 年 6 月 17 日
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 件)

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by