Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Why does the time I tell about the graph vary?

1 view (last 30 days)
Erwin Avendaño
Erwin Avendaño on 3 Dec 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
According to me, I am measuring the time since the data arrives to the cell (1,50) -> v2(1,50) but, matlab is giving me different values when executing my code, why does this happen? I want to measure the time from when you start graphing to the value of 90 (that is, cell (1,50)) [I put a break to stop graphing at the point where I want to finish counting time, I am sending the data from arduino to matlab]
fa.png
function arduinomatlab
v1=zeros(1,1000);
v2=zeros(1,1000);
delete(instrfind({'Port'},{'COM3'}));
s = serial('COM3','BaudRate',9600,'Terminator','CR/LF');
warning('off','MATLAB:serial:fscanf:unsuccessfulRead');
fopen(s);
muestras=1;
figure('Name','Captura');
xlh = xlabel ( 'Grados' );
ylim([-1 1]);
xlim([0 369]);
ax = gca;
ax.XAxisLocation = 'origin';
xticks([30,60,90,120,150,180,210,240,270,300,330,360])
ylabel('Y')
title('Onda Sinouidal')
grid on
hold on
while 1
try
valor=fscanf(s, '%f,%f')';
v2(muestras)=(valor(2));
tic
v1(muestras)=(valor(1));
if v2(1,50)
tiempo=toc;
disp(tiempo);
break
end
plot(v2(1:muestras),v1(1:muestras),'-k')
drawnow
muestras=muestras+1;
catch
break
end
end
fclose(s);
delete(s);
clear s;
end

Answers (0)

This question is closed.

Tags

Community Treasure Hunt

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

Start Hunting!