How do I plot arduino data with time running in x axis

5 次查看(过去 30 天)
Dear all,
I am stuck in a certain problem where I am getting the data from matlab with respect to the count of iterations. I want it with respect to time so thati perform fft later on for the data. Please help!
clc, clear all;
A=zeros(1,1000);
B=zeros(1,1000);
count = 0;
N=100;
time=(1:N/4);
delete(instrfind({'Port'},{'COM14'}));
s = serial('COM14', 'BaudRate', 115200);
fopen(s);
while(count<=1000)
a=fscanf(s,'%d');
count=count+1;
A(1,count)=a;
B(1,count)=A(count)*.000185;
disp(a);
end
fclose(s);
disp(B)
plot(B) I WANT TO PLOT THIS DATA WITH RESPECT TO TIME ON X AXIS
%plot(abs(fft(B)))

回答(1 个)

Mark Sherstan
Mark Sherstan 2019-5-17
Use tic and toc to record time. I updated your code below!
clc, clear all;
A=zeros(1,1000);
B=zeros(1,1000);
C=zeros(1,1000);
count = 0;
N=100;
time=(1:N/4);
delete(instrfind({'Port'},{'COM14'}));
s = serial('COM14', 'BaudRate', 115200);
fopen(s);
tic
while(count<=1000)
a=fscanf(s,'%d');
count=count+1;
A(1,count)=a;
B(1,count)=A(count)*.000185;
C(1,count)=toc;
disp(a);
end
fclose(s);
disp(B)
plot(C,B) %I WANT TO PLOT THIS DATA WITH RESPECT TO TIME ON X AXIS
%plot(abs(fft(B)))

类别

Help CenterFile Exchange 中查找有关 MATLAB Support Package for Arduino Hardware 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by