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!