Info

Questa domanda è chiusa. Riaprila per modificarla o per rispondere.

Why does the time I tell about the graph vary?

2 visualizzazioni (ultimi 30 giorni)
Erwin Avendaño
Erwin Avendaño il 3 Dic 2019
Chiuso: MATLAB Answer Bot il 20 Ago 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

Risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by