アナログ入力によって取得した複数のデータを個別のグラフにプロットしたい
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
現在実行しているコードでは、オレンジ色と青色の線で重なってプロットされているため、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);
現在のコードを実行すると得られるグラフをスクリーンショットで撮ったもの

0 Kommentare
Akzeptierte Antwort
Kazuya
am 25 Apr. 2019
Bearbeitet: Kazuya
am 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の行列だと仮定しています。)
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Title 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!