define delay time in a for cylce in matlab
Publicado por Gabriel (1 intervención) el 07/04/2013 21:20:28
Hi, I need to do matlab data acquisition, but I need control the rate and amount of data stored in a vector. I made a "for cycle", but I need that the cycle takes place each unit time defined, up to the total acquisition time. I mean, if t=1, I need 500 samples stored in a second, one each 0.002ms. How I can do that?. Thanks!
clc
t=1;
v1=zeros(1,500*t);
delete(instrfind({'Port'},{'COM3'}))
s = serial('COM3');
set(s,'BaudRate',9600);
s.inputbufferSize = 10000;
delay= wait time = frecuency of data
fopen(s);
for i=1:t*500;
a=fscanf(s,'%d');
v1(i)=a
i=i+1;
wait time
end
fclose(s);
clc
t=1;
v1=zeros(1,500*t);
delete(instrfind({'Port'},{'COM3'}))
s = serial('COM3');
set(s,'BaudRate',9600);
s.inputbufferSize = 10000;
delay= wait time = frecuency of data
fopen(s);
for i=1:t*500;
a=fscanf(s,'%d');
v1(i)=a
i=i+1;
wait time
end
fclose(s);
Valora esta pregunta


0