Updating the plot problem while using refreshdata
14 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Stella
el 17 de En. de 2024
Hi!! I was having a problem on my code while using the refreshdata, and I was hoping for your help. I want to see the actual first peak and valley from my data, then update the plot after passing them until i reach the last value in my data. I tried first to just run the whole data, but I am already stuck with it and just keep getting the whole data, and was fast too. I was actually planning to use it for the succeeding codes that I already have and for a real-time signal analysis.
I am not used to Matlab coding too so bear with me please.
Here is the code I made
%raw data from XYZ direction
NormChest = readtable('Tidal/TV_500ml.csv'); %%%get the raw data
C = table2array(NormChest(:,1));
x = table2array(NormChest(:,2));
y = table2array(NormChest(:,4));
z = table2array(NormChest(:,6));
total = table2array(NormChest(:,8));
time = C(:,1);
%--------------------------------------------------------------------------
% get relative acceleration
x = x - mean(x);
y = y - mean(y);
z = z - mean(z);
total = total - mean(total);
% % plot for raw data
% figure (1)
% plot (time, x, time, y, time, z, time, total), legend('x','y','z','total'); axis tight;
% title ("Subject 1 (500 mL)")
%--------------------------------------------------------------------------
%partial delay %Still having difficulty here
x1 = time; %trial
y1 = z; %trial
h = plot (x1, y1);
h.XDataSource = 'x1';
h.YDataSource = 'y1';
for i = 0:20
refreshdata (h, 'caller');
drawnow;
end
%
%
% for i = 1:1:numel (time)
%
% % refreshdata;
% end
0 comentarios
Respuesta aceptada
Avni Agrawal
el 17 de En. de 2024
Hi Stella,
I understand that you are trying to create a plot that updates in real-time, showing the first peak and valley of your data, and then updating the plot as you step through the data. The `refreshdata` function is used to update plots when the data source has changed, but in your case, you need to update the data source incrementally.
Here's a revised version of your code that will create an animated plot. This example uses a for-loop to simulate real-time data plotting by updating the plot with one data point at a time and then pausing briefly. This should give you the effect of the plot being drawn in real-time. Note that for large datasets, you may need to adjust the pause duration to control the speed of the animation.
% Read the data from the CSV file
NormChest = readtable('Tidal/TV_500ml.csv');
% Extract data from the table
time = NormChest{:, 1};
x = NormChest{:, 2} - mean(NormChest{:, 2});
y = NormChest{:, 4} - mean(NormChest{:, 4});
z = NormChest{:, 6} - mean(NormChest{:, 6});
total = NormChest{:, 8} - mean(NormChest{:, 8});
% Initialize the plot
figure(1);
h = plot(time(1), z(1), 'b'); % Start with the first data point
hold on; % Keep the plot for updating
xlabel('Time');
ylabel('Z-axis acceleration');
title('Subject 1 (500 mL) - Real-time Signal Analysis');
axis tight; % Set the axis limits to the range of the data
% Set the data source properties for dynamic updating
h.XDataSource = 'x1';
h.YDataSource = 'y1';
% Loop through the data to simulate real-time plotting
for i = 2:length(time)
% Update the data source
x1 = time(1:i);
y1 = z(1:i);
% Update the plot
refreshdata(h, 'caller');
drawnow;
% Pause for a brief moment to simulate real-time data acquisition
pause(0.01); % Adjust the pause duration as needed
end
hold off; % Release the plot
This code will create a figure and plot the first data point. Then, in the loop, it will incrementally add one data point at a time to the plot and refresh the figure with `refreshdata`. The `pause` function is used to slow down the loop to simulate real-time plotting. You can adjust the duration of the pause to match the speed of your actual data acquisition or desired visualization speed.
I hope this helps.
1 comentario
Más respuestas (0)
Ver también
Categorías
Más información sobre Geographic Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!