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 件のコメント

dpb
dpb 2016 年 3 月 22 日
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 2016 年 3 月 22 日
Thom Wit’s ‘Answer’ moved here:
Ok so i want it not to change color for each graph every iteration

サインインしてコメントする。

回答 (1 件)

Star Strider
Star Strider 2016 年 3 月 22 日

0 投票

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 件のコメント

Thom Wit
Thom Wit 2016 年 3 月 23 日
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 2016 年 3 月 23 日
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.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeGraphics Performance についてさらに検索

質問済み:

2016 年 3 月 22 日

コメント済み:

2016 年 3 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by