saving data of loop iteration
1 view (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!