MATLAB real-time graph proterties

1 visualizzazione (ultimi 30 giorni)
John Smith
John Smith il 20 Mar 2016
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

Risposte (0)

Categorie

Scopri di più su Publishers and Subscribers in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by