saving data of loop iteration

1 次查看(过去 30 天)
ayman dhafer
ayman dhafer 2020-6-7
Hi every one
I have read data from arduino to matlab through serial port. I nead the data to sent from sensor to matlab at every half second but I want the data to be saved each iteration of the for loop. here is the code I have used
% clear all
instrreset
clc
n=1000;
arduino=serial('COM6','BaudRate',250000);
fopen(arduino);tic
for j=1:4
for i=1:n
d =fscanf(arduino,'%c');
IncomingString = char(d);
IncomingString = regexp(IncomingString, '\s*', 'split');
mic1(i,1)= str2double(IncomingString(1,1));
mic2(i,1)=str2double(IncomingString(1,2));
mic3(i,1)=str2double (IncomingString(1,3));
mic4(i,1)=str2double (IncomingString(1,4));
mic5(i,1)= str2double(IncomingString(1,5));
mic6(i,1)=str2double(IncomingString(1,6));
end
data=[mic1 mic2 mic3 mic4 mic5 mic6];
data(isnan(data))=500;data(data > 700) = 500;toc
plot(data)
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by