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

3 Ansichten (letzte 30 Tage)
Abdul Azeez Khan
Abdul Azeez Khan am 8 Mai 2019
Beantwortet: Mark Sherstan am 17 Mai 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)))

Antworten (1)

Mark Sherstan
Mark Sherstan am 17 Mai 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)))

Kategorien

Mehr zu MATLAB Support Package for Arduino Hardware finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by