- Use a while loop to continuously check for new data.
- Use readtable or xlsread to import data from the Excel file.
- Refresh the plot with the new data.
- Use pause to wait for a specific duration (e.g., 60 seconds) before checking for new data again.
plotting live data in matlab
2 ビュー (過去 30 日間)
古いコメントを表示
hi, i get data imported every minute via excel. I want to plot this data as realtime in a graph so it gets updates automatically. how can i do this? any ideas?
0 件のコメント
回答 (1 件)
Himanshu
2024 年 12 月 10 日
Hey,
To read and plot and live data from an axcel into Matlab, you can setup a loop that constantly reads from the excel and keeps updating the plot. Here is how you can do it:
Here is the sample code for the same:
% Initialize figure
figure;
hold on;
% Infinite loop to update the plot
while true
% Read data from the Excel file
data = readtable('yourfile.xlsx'); % Replace 'yourfile.xlsx' with your Excel file name
% Extract the relevant columns for plotting (assuming 'Time' and 'Value' for now)
timeData = data.Time;
valueData = data.Value;
% Clear the current plot
cla;
% Plot the new data
plot(timeData, valueData, '-o');
% Update plot title and labels
title('Real-Time Data Plot');
xlabel('Time');
ylabel('Value');
% Pause for 60 seconds before updating again
pause(60);
end
Hope this helps!
1 件のコメント
Walter Roberson
2024 年 12 月 10 日
Note that the cla is not needed there. Just remove the "hold on".
Unless, that is, you want to plot the cumulative data, despite the fact that the same data might be read twice (if the file does not update.) But on that case, you would remove the "cla"
There are more efficient ways to do the plotting, but the details depend on whether you want cumulative plotting or just to plot the current contents of the file.
参考
カテゴリ
Help Center および File Exchange で Bar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!