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

2 ビュー (過去 30 日間)
horizon
horizon 2019 年 4 月 24 日
編集済み: horizon 2019 年 4 月 25 日
現在実行しているコードでは、オレンジ色と青色の線で重なってプロットされているため、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);
現在のコードを実行すると得られるグラフをスクリーンショットで撮ったもの

採用された回答

Kazuya
Kazuya 2019 年 4 月 25 日
編集済み: Kazuya 2019 年 4 月 25 日
データ元がないので推測ですが、プロットを描いている下記関数をいじればなんとかなりそうな気がします。
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の行列だと仮定しています。)

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!