필터 지우기
필터 지우기

MATLAB real-time graph proterties

조회 수: 1 (최근 30일)
John Smith
John Smith 2016년 3월 20일
Hi,
I found the MATLAB code below from MBED website. This is used to display a real-time plot of five analog signals from a microcontroller. The plot is set to start from the beginning (position 1 of the x-axis) of the window when the X-axis duration is reached. How can I modify the code so that the new values are uploaded to the end on the graph rather then starting from the beginning?
TIMEOUT = 5; %time to wait for data before aborting
XPOINTS = 100; %number of points along x axis
try
%create serial object to represent connection to mbed
mbed = serial('COM5', ...
'BaudRate', 9600, ...
'Parity', 'none', ...
'DataBits', 8, ...
'StopBits', 1); %change depending on mbed configuration
set(mbed,'Timeout',TIMEOUT); %adjust timeout to ensure fast response when mbed disconnected
fopen(mbed); %open serial connection
position = 1; %initialise graph variables
time = 1;
x = [(1:XPOINTS)' (1:XPOINTS)' (1:XPOINTS)' (1:XPOINTS)' (1:XPOINTS)'];
xlabels = (1:XPOINTS);
y = zeros(XPOINTS,5);
while (1) %loop forever (or until an error occurs)
values = fscanf(mbed, '%f,%f,%f,%f,%f'); %get values into vector
%assumes data formatted as
%'1,2,3'
y(position,:) = values'; %put into y to be displayed
%update position on x-axis and x-axis labels
xlabels(position) = time;
time = time + 1;
if (position < XPOINTS)
position = position + 1;
else
position = 1;
end
%display
plot(x,y);
set(gca, 'XTick', 1:XPOINTS);
set(gca, 'XTickLabel', xlabels);
drawnow; %this is required to force the display to update before the function terminates
end
fclose(mbed); %close connection (this should never be reached when using while(1), but included for completeness)
catch
%in case of error or mbed being disconnected
disp('Failed!');
fclose(mbed); %close connection to prevent COM port being lokced open
end

답변 (0개)

카테고리

Help CenterFile Exchange에서 Publishers and Subscribers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by