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
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
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
2016 年 3 月 22 日
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
2016 年 3 月 23 日
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 Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!