0
我MATLAB接口与一个Arduino的电路工程密谋改变向量。我想轮询Arduino在给定传感器上感应到的电压,将该电压添加到一个矢量,然后将它全部绘制在同一个循环内。我有前两个部分,但我似乎无法弄清楚如何反复绘制电压矢量,因为它变得更长。有没有办法做到这一点?MATLAB在while循环
%{
Ventilation Rate Sensor v0.1
This program uses a thermistor connected to pin A0 and analyzes the
difference in voltage drop in order to assess the user's ventilation rate.
Designed for use with a voltage divider using a 2.2kOhm resistor and a
10kOhm (at 25C) thermistor in series. Note that this REQUIRES the Arduino
to have the code for MATLAB interface already installed. This is included
in the MATLAB Arduino software page at
<<http://www.mathworks.com/matlabcentral/fileexchange/
32374-matlab-support-package-for-arduino-aka-arduinoio-package>>
%}
clc
clear
close all
ard = arduino('COM3');
voltage = [];
timer = datenum(clock+[0,0,0,0,0,30]);
while datenum(clock) < timer
sensorValue = ard.analogRead(0);
voltage = [voltage (sensorValue * (5/1023))];
hold on;
t = [1:1:length(voltage)];
plot(t,voltage)
end
谢谢!这工作得很好。 – SciurusDoomus
@SciurusDoomus很高兴帮助。另外,请参阅编辑答案与另一个可能有用的想法 –
有趣。我并不需要削减运行时间,因为绘图比我想要输出的实际数据更像是一种测试机制。但是,我相信我将来需要它,或者让这个程序在真正旧的系统上可用。谢谢! – SciurusDoomus