How can I plot data in loop from array ?

Hi I have a question how to plot data in loop from array that the graphs would be in different colors (i manage to do that but colors are changing in each iteration of the loop and this is not good enough.
In code i'm taking some data from usb device there are in this shape e.g. : "21.09,0.18,-0.20,0.96,-0.11,1.88,-0.89,0,0,0".
Here is my code:
% code
clear all;
clc;
close all;
delete(instrfindall);
s = serial('COM5')
set(s,'BaudRate', 38400);
set(s,'DataBits', 8);
set(s,'StopBits', 1);
fopen(s);
s.ReadAsyncMode = 'continuous';
t=1;
% Main graph figure
figure(1);
hold on;
title('Incomming Data from External Device');
xlabel('time');
ylabel('Value');
legend('a','d','f','g')
while(t <= 400)
data =fscanf(s);
IncomingString = char(data);
C = str2num(IncomingString);
for n = 1:10
A(t,n) = C(n)
end
plot (A)
axis auto;
grid on;
axis([0 inf -250 250])
drawnow;
t=t+1;
end
fclose(s);
I think that plot(A) should be used differently but i don't know how.
Please help me.

2 comentarios

dpb
dpb el 22 de Mzo. de 2016
Tell us what you want the graph to be; we can't run your code and so to try to figure out from it alone is tough...
Star Strider
Star Strider el 22 de Mzo. de 2016
Thom Wit’s ‘Answer’ moved here:
Ok so i want it not to change color for each graph every iteration

Iniciar sesión para comentar.

Respuestas (1)

Star Strider
Star Strider el 22 de Mzo. de 2016
If you want the colours to be the same, tell it to plot in a specific colour you choose (here, green):
plot(A, 'g')

2 comentarios

Thom Wit
Thom Wit el 23 de Mzo. de 2016
If i would do this i will get all graphs in e.g. green and i want them to have different colors but not in each iteration
Star Strider
Star Strider el 23 de Mzo. de 2016
I can’t run your code so I can’t test this, and I’m not certain what you want to do.
See if setting the 'ColorOrder' for the plot each time will do what you want. See the documentation for Line Styles Used for Plotting — LineStyleOrder for details.

Iniciar sesión para comentar.

Categorías

Más información sobre Graphics Performance en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 22 de Mzo. de 2016

Comentada:

el 23 de Mzo. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by