How to remove gaps in timeseries plot to have a continuous graph

조회 수: 15 (최근 30일)
Sachin Hegde
Sachin Hegde 2024년 7월 31일
댓글: Sachin Hegde 2024년 7월 31일
Hello Everyone,
I have a timeseries data from a vehicle having gaps in it. FOr example, when the vehicle was running, there is data, but no data is available when the vehicle is turned off. When i plot now, the missig data is filled witha line connecting last measured data to the next measured data (see figure). How can i remove that line and instead have a continuous line.
I highly appreciate for any efforts.
  댓글 수: 3
Stephen23
Stephen23 2024년 7월 31일
"How can i remove that line and instead have a continuous line."
It is already a continuous line.
Your requirement is unclear.
Sachin Hegde
Sachin Hegde 2024년 7월 31일
Hi Stephan, sorry for my miscommunication. I just want to chop that connecting line and join the data before and after. I hopw thins is a better explaination of the requirement.

댓글을 달려면 로그인하십시오.

답변 (2개)

Alan Stevens
Alan Stevens 2024년 7월 31일
Include a NaN in the data list between each data set.

Pavan Sahith
Pavan Sahith 2024년 7월 31일
편집: Pavan Sahith 2024년 7월 31일
Hello Sachin ,
It appears you are trying to handle gaps in your time series data and prevent MATLAB from connecting the missing data points with a line,
you can try replacing the gaps with NaN values. When you plot the data, MATLAB will automatically break the line at these NaN values, resulting in a plot where only continuous data points are connected.
Here's an example using some sample data:
% Sample data with gaps
time = [1, 2, 3, 7, 8, 9, 15, 16, 17]; % Time points
data = [10, 12, 15, 20, 18, 22, 25, 24, 27]; % Corresponding data points
% Introduce gaps in the data
data_with_gaps = data;
data_with_gaps([4, 7]) = NaN; % Assuming data points at time 7 and 15 are missing
% Plot the data
figure;
plot(time, data_with_gaps, '-o');
xlabel('Time');
ylabel('Data');
title('Time Series Data with Gaps');
grid on;
This approach might help, that your plot accurately reflects the discontinuities in your data, providing a clearer visualization of periods where the vehicle was turned off.
you can refer to the following MathWorks documentation to know more
Hope this helps you in moving forward
  댓글 수: 5
Sachin Hegde
Sachin Hegde 2024년 7월 31일
@Stephen23 Makes sense. Thank you for the tip.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Multirate Signal Processing에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by