How can I slow down the plotting speed?

32 ビュー (過去 30 日間)
horizon
horizon 2019 年 5 月 1 日
コメント済み: Walter Roberson 2019 年 5 月 4 日
I would like to change the plotting speed of the following code.
I've tried to edit the TimeStamps part like these
subplot(2,1,1)
plot(t1/100,s1)
ylim([-10.0 10.0]);
title('s_1')
subplot(2,1,2)
plot(t1/100,s2)
ylim([-10.0 10.0]);
title('s_2')
xlabel('Time (s)')
but the plotting speed was not changed.
Entire Code
tx = daq.createSession('ni');
s = daq.createSession('ni');
s.Rate = 400000;
ultraFreq = 40000;
numCycle =8
addAnalogOutputChannel(tx, 'Dev1', 'ao0', 'Voltage');
th=addlistener(tx, 'DataRequired', @queueMoreData);
addAnalogInputChannel(s,'Dev1', 'ai0', 'Voltage');
ch = addAnalogInputChannel(s, 'Dev1', 'ai1', 'Voltage');
h = addlistener(s, 'DataAvailable', @plotData);
s.DurationInSeconds(1);
queueOutputData(tx, y');
startBackground(s);
tx.startForeground();
function plotData(src, event)
t1 = event.TimeStamps(:,1);
s1 = event.Data(:,1);
s2 = event.Data(:,2);
subplot(2,1,1)
plot(t1,s1)
ylim([-10.0 10.0]);
title('s_1')
subplot(2,1,2)
plot(t1,s2)
ylim([-10.0 10.0]);
title('s_2')
xlabel('Time (s)')
end
function queueMoreData(src, event)
queueOutputData(tx, y');
end

採用された回答

KSSV
KSSV 2019 年 5 月 1 日
Read about pause
  2 件のコメント
horizon
horizon 2019 年 5 月 4 日
I wrote the following code in Python and figured out 'interval' was the variable for the plotting speed in this case.
As you introduced me, I've read the MATLAB document for pause, but I am still troubled with the way to use it on MATLAB.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import itertools
import math
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import animation
def _update(frame, x, y):
"""function to update graph"""
# clear the real time data
plt.cla()
# update and append the data
x.append(frame)
y.append(math.sin(frame))
# rewrite graph
plt.plot(x, y)
def main():
# area to plot
fig = plt.figure(figsize=(10, 6))
# data to plot
x = []
y = []
params = {
'fig': fig,
'func': _update, # function to update graph
'fargs': (x, y), # arguments for the function
'interval': 10, # frequency to update (ms)
'frames': itertools.count(0, 0.1), # itertool to create infinite frames
}
anime = animation.FuncAnimation(**params)
# plot graph
plt.show()
if __name__ == '__main__':
main()
Walter Roberson
Walter Roberson 2019 年 5 月 4 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by