plotting few values continuously in real time

9 ビュー (過去 30 日間)
Mamudi
Mamudi 2012 年 4 月 12 日
コメント済み: Walter Roberson 2025 年 2 月 3 日 19:21
i have data coming from the gps and i want to plot it for every one second. like a ecg graph. the values are like 560,940,780. please help

回答 (1 件)

ag
ag 2025 年 2 月 3 日 18:30
To plot GPS data in real-time, similar to an ECG graph, you can utilize MATLAB's animatedline function within a loop that updates the plot every second. Below is a structured approach to achieve this:
% Initialize the figure and animated line
figure;
h = animatedline('LineWidth', 2); % Bold line for clear visibility
ax = gca; % Get current axes
ax.YGrid = 'on'; % Add grid for better visualization
xlabel('Time (s)');
ylabel('GPS Value');
title('Real-Time GPS Data Plot');
% Simulate incoming GPS data (replace this with your actual data)
gps_data = [560, 940, 780, 600, 880, 720, 650, 900, 780]; % Example data
time_interval = 1; % 1-second interval
t = 0; % Initialize time counter
% Example for reading from a serial port (adjust COM port and settings)
s = serialport('COM3', 9600); % Replace 'COM3' and baud rate as needed
while true % modify the breaking condition accordingly
data = readline(s); % Read GPS data from the device
gps_value = str2double(data); % Convert string to numeric
t = t + 1;
addpoints(h, t, gps_value);
drawnow;
pause(1);
end
For more details, please refer to the following MathWorks documentations:
  • animatedline - https://www.mathworks.com/help/matlab/ref/animatedline.html
  • serialport - https://www.mathworks.com/help/matlab/ref/serialport.html
  • readline - https://www.mathworks.com/help/instrument/serialport.readline.html
  • addpoints - https://www.mathworks.com/help/matlab/ref/addpoints.html
  • drawnow - https://www.mathworks.com/help/matlab/ref/drawnow.html
Hope this helps!
  1 件のコメント
Walter Roberson
Walter Roberson 2025 年 2 月 3 日 19:21
Note:
animatedline() and addpoints() were not available at the time this question was originally asked.
serialport() and readline() were not available at the time this question was originally asked.

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

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by