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

5 visualizaciones (últimos 30 días)
Abdul Azeez Khan
Abdul Azeez Khan el 8 de Mayo de 2019
Respondida: Mark Sherstan el 17 de Mayo de 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)))

Respuestas (1)

Mark Sherstan
Mark Sherstan el 17 de Mayo de 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)))

Categorías

Más información sobre MATLAB Support Package for Arduino Hardware en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by