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 Kommentare

dpb
dpb am 22 Mär. 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 am 22 Mär. 2016
Thom Wit’s ‘Answer’ moved here:
Ok so i want it not to change color for each graph every iteration

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Star Strider
Star Strider am 22 Mär. 2016

0 Stimmen

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 Kommentare

Thom Wit
Thom Wit am 23 Mär. 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 am 23 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Performance finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 22 Mär. 2016

Kommentiert:

am 23 Mär. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by