Why don't you draw the line of vectors on the graph?

1 view (last 30 days)
I have 2 data vectors, where the data comes from Arduinos until everything is fine there. I graph the points and everything is fine. What happens is that when I want those points to have a line, that is, a trend line, a line that passes through all these points is not plotted. I do not understand why? I mean the points are only plotted, but the line is not plotted. Thanks for reading me
ANNEX CAPTURE URL OF HOW SHOULD BE LEFT(https://twitter.com/EH_38/status/1201419564661248000/photo/1)
ANNEX CAPTURE URL OF HOW I GET MY GRAPH IN SCRIPT(https://twitter.com/EH_38/status/1201420265466531840/photo/1)
<<<CODE>>>
function arduinomatlab
n=21
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');
xlabel('Tiempo')
ylabel('Aceleracion')
title('Acelerograma')
grid on
hold on
while 1<=n
ylim([0 240]);
xlim([0 0.5]);
valor=fscanf(s, '%f,%f')';
v2(muestras)=(valor(2));
v1(muestras)=(valor(1));
plot(v2(muestras),v1(muestras),'x-')
drawnow
muestras=muestras+1;
end
fclose(s);
delete(s);
clear s;
end

Accepted Answer

ME
ME on 2 Dec 2019
I think this is because you are plotting inside your while loop. Here you are telling it to plot one data point each time and so it can't join them up because it doesn't know they should be connected.
Your best bet to fix this would be to store all of your v1 and v2 data points up and then plot them at the end of the script.
Alternatively, if you need them to plot as the script is running then I think you'll have to change your plot command to something like:
plot(v2(1:muestras),v1(1:muestras),'x-')
although this will plot over the top of the previous line so you will end up with a whole bunch of lines that cover an gradually increasing portion of the x-axis. If you only want the last line in your plot then you could try looking at the following link to remove the last plotted line before adding your new one.
  2 Comments

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by