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

3 views (last 30 days)
Abdul Azeez Khan on 8 May 2019
Answered: Mark Sherstan on 17 May 2019
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)))

Mark Sherstan on 17 May 2019
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)))