Why don't you draw the line of vectors on the graph?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Erwin Avendaño
am 2 Dez. 2019
Kommentiert: Erwin Avendaño
am 2 Dez. 2019
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
0 Kommentare
Akzeptierte Antwort
ME
am 2 Dez. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!