我希望你能帮助我。
我已将3个传感器连接到Arduino,我同时将数据发送到串口。
arduino代码是
unsigned int pres;
unsigned int temp;
unsigned int fluidrate;
void setup()
{
Serial.begin(9600);
}
void loop()
{
pres = analogRead(0);
temp = analogRead(1);
fluidrate = analogRead(2);
Serial.print(pres);
Serial.print("\t");
Serial.print(temp);
Serial.print("\t");
Serial.print(fluidrate);
Serial.print("\n");
delay(1000);
} arduino串行监视器中的数据是
257 7 14
273 23 46
327 77 154
340 90 180
345 95 190
352 102 204
Matlab代码是
clear all
clc
arduino=serial('COM8','BaudRate',9600);
fopen(arduino);
x=linspace(1,100);
numcols = 1;
y = {};
for i=1:length(x);
data =fscanf(arduino,'%f');
IncomingString = char(data);
IncomingString = regexp(IncomingString, '\s*', 'split');
pres(i,1)= IncomingString(1,1);
temp(i,1)= IncomingString(1,2);
fluidrate(i,1)= IncomingString(1,3);
end
fclose(arduino);
Plotpres = str2double(pres);
figure(1)
plot(Plotpres);
title('pressure'); xlabel('Samples'); ylabel('pres in bar');
Plottemp = str2double(temp);
figure(2)
plot(Plottemp);
title('temperature'); xlabel('Samples'); ylabel('temp in C');
Plotfluidrate = str2double(fluidrate);
figure(3)
plot(Plotfluidrate);
title('fluidrate'); xlabel('Samples'); ylabel('fluidrate in l/min');
我收到错误???使用==>时出错regexp第一个参数(STRING)必须是char或字符串数组的一维数组。
==>中的错误monitorystem at 11 IncomingString = regexp(IncomingString,'\ s *','split');
请帮助我获取输出