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

5 views (last 30 days)
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)))

Answers (1)

Mark Sherstan
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)))

Categories

Find more on MATLAB Support Package for Arduino Hardware in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!