アナログ入力によって​取得した複数のデータ​を個別のグラフにプロ​ットしたい

9 views (last 30 days)
horizon
horizon on 24 Apr 2019
Edited: horizon on 25 Apr 2019
現在実行しているコードでは、オレンジ色と青色の線で重なってプロットされているため、subplotで描画したいです。
以下のようにMATLAB上で作成した式をsubplotで個別に描画することはできますが、時間が経過するに従ってx軸が移動するようにした現在実行しているコードでは、どの部分でどうやってsubplotを実装すればいいかわかりません。
t1 = (0:length(s1)-1)/Fs;
t2 = (0:length(s2)-1)/Fs;
subplot(2,1,1)
plot(t1,s1)
title('s_1')
subplot(2,1,2)
plot(t2,s2)
title('s_2')
xlabel('Time (s)')
現在のコード
s = daq.createSession('ni');
tx = daq.createSession('ni');
y = [y zeros(1,numCycle*s.Rate/ultraFreq)];
addAnalogOutputChannel(tx, 'Dev1', 'ao0', 'Voltage');
th=addlistener(tx, 'DataRequired', @queueMoreData);
addAnalogInputChannel(s,'Dev1', 'ai0', 'Voltage');
addAnalogInputChannel(s, 'Dev1', 'ai1', 'Voltage');
h = addlistener(s, 'DataAvailable', @plotData);
s.DurationInSeconds(1);
queueOutputData(tx, y');
startBackground(s);
現在のコードを実行すると得られるグラフをスクリーンショットで撮ったもの

Accepted Answer

Kazuya
Kazuya on 25 Apr 2019
Edited: Kazuya on 25 Apr 2019
データ元がないので推測ですが、プロットを描いている下記関数をいじればなんとかなりそうな気がします。
function plotData(src, event)
plot(event.TimeStamps, event.Data);
% xlim([0 10]);
ylim([-0.1 0.1]);
if (max(event.Data(:,1))>0.3)
%eventtriger = event.Data;
dd = event.Data(:,1);
end
end
event.TimeStamps event.Data がどういうサイズ(ベクトルなのか行列なのか・・)によるんですが、もし2つの時系列データが確保されているのであれば、
function plotData(src, event)
t1 = event.TimeStamps(:,1);
t2 = event.TimeStamps(:,2);
s1 = event.Data(:,1);
s2 = event.Data(:,2);
subplot(2,1,1)
plot(t1,s1)
ylim([-0.1 0.1]);
title('s_1')
subplot(2,1,2)
plot(t2,s2)
ylim([-0.1 0.1]);
title('s_2')
xlabel('Time (s)')
end
など、、それぞれ別々にプロットしてやるとか。いかがでしょうか? (event.TimeStamps と event.Data はともに Nx2の行列だと仮定しています。)

More Answers (0)

Categories

Find more on 2 次元および 3 次元プロット in Help Center and File Exchange

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!