필터 지우기
필터 지우기

複数のアナログ入力値​は取得できるのにプロ​ットができない

조회 수: 1 (최근 30일)
horizon
horizon 2019년 4월 24일
답변: Kazuya 2019년 4월 26일
以下のプログラムで2つのアナログ入力値をプロットしようとしています。
しかし、出力では値は両方とも得られるのにプロットは片方のアナログ入力のみが行われ、もう一方はエラーが出て描画されません。
どうしたらこのエラーを回避できるプログラムにできますか?
なぜ1つ目のアナログ入力のみ描画されるのでしょうか?
%送信波と受信波をプロットするプログラム
s = daq.createSession('ni');
tx = daq.createSession('ni');
ch1 = addAnalogInputChannel(tx,'Dev1', 'ai0', 'Voltage');
ch2 = addAnalogInputChannel(s,'Dev1', 'ai1', 'Voltage');
s.Rate = 8000;
data1 = tx.inputSingleScan;
data2 = s.inputSingleScan;
disp(data1)
disp(data2)
%送信側プロット
subplot(2,1,1)
tx.DurationInSeconds = 2;
[data1,time] = tx.startForeground;
plot(time,data1);
%disp(time);
%disp(data);
xlabel('Time (secs)');
ylabel('Voltage')
%受信側プロット
subplot(2,1,2)
s.DurationInSeconds = 5;
[data2,time] = s.startForeground;
plot(time,data2);
%disp(time);
%disp(data);
xlabel('Time (secs)');
ylabel('Voltage')
%受信側の最大振幅を求める
[up,lo] = envelope(data2, 300);
maxAmplitude = peak2peak(up-lo);
disp(maxAmplitude)
出力
>>showOutputInput
5.3680e-04
2.4084
エラー:showOutputInput(line 37)
The hardware associated with this session is reserved. If you are using it in another
session use the release function to unreserve the hardware. If you are using it in an
external program exit that program. Then try this operation again.
  댓글 수: 1
Shoumei
Shoumei 2019년 4월 26일
편집: Shoumei 2019년 4월 26일
DAQが無くて再現できないので、ご自身で1行1行実行して、どこでエラーが発生しているか確認してはいかがでしょうか?
あと、envelopeで最大振幅を求めるのは間違った使い方です。最大、最小値を取り逃す可能性があります。

댓글을 달려면 로그인하십시오.

채택된 답변

Kazuya
Kazuya 2019년 4월 26일
data1 = tx.inputSingleScan;
data2 = s.inputSingleScan;
disp(data1)
disp(data2)
の部分では data1data2 もデータは取れているんですか?

추가 답변 (0개)

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!