Plotting datapoints with their time distance on x-axis

2 views (last 30 days)
Hello everyone!
I want to ask something but i'm not sure if iteven possible to do that. I have data that looks like this (only a small part of it):
What my code does is getting the timedifference of each pair (sometimes there are 3 points, sometimes 4, but i'm only interested in the first and last one) and calculates the travelled distance between those points. The result looks like this (the red line is not of interest):
What i'm supposed to do is match the travelled distance to the timepoints above. If I have to describe the expected result, i would say the following: the travelled distance between aprox. 100.5s and 102s is 12cm, after that it is 16cm from 102s till 105s and so on.. I hope you get what I mean.
I attached the needed data in question.mat. To get the plots above i did the following:
load question.mat
r_Trommel = 1;
hold on
hold off
while (k>=1) && (k<=length(max_XWerte)-3)
if (abs(max_XWerte(k+3)-max_XWerte(k))> 0.05) && (abs(max_XWerte(k+3)-max_XWerte(k))< 0.08)
laenge(k) = abs(max_XWerte(k+3)-max_XWerte(k))*(kmh/3.6);
k = k+4;
elseif (abs(max_XWerte(k+2)-max_XWerte(k))>= 0.03) && (abs(max_XWerte(k+2)-max_XWerte(k))< 0.09)
laenge(k) = abs(max_XWerte(k+2)-max_XWerte(k))*(kmh/3.6);
laenge(k) = abs(max_XWerte(k+1)-max_XWerte(k))*(kmh/3.6);
for m=1:length(laenge)
if laenge(m) == 0
laenge(m) = laenge(m-1);
for f=1:length(laenge)
Thank you in advance!!

Accepted Answer

Cris LaPierre
Cris LaPierre on 31 Mar 2022
Edited: Cris LaPierre on 31 Mar 2022
It's hard to say for certain, since you have not shown how the times correspond to your step plot, but here's some simple code that may get you close. It is wrong because max_XWerte has more elements than l_test, so the last few times in max_XWerte are not used.
load KPvars.mat % variables created by your code
% Find the index of each step change
step = [1 find(abs(diff(l_test))>0.0001)+1];
% use indeces to find the start and stop time of each step
start = max_XWerte(step(1:end-1));
stop = max_XWerte(step(2:end));
% use indices to find the corresponding distance traveled
dist = l_test(step(1:end-1))';
% Combine into a table
T = table(start,stop,dist)
T = 44×3 table
start stop dist ______ ______ ______ 100.54 102.69 12.508 102.69 107.72 16.686 107.72 110.6 12.508 110.6 112.77 20.871 112.77 113.49 12.508 113.49 117.07 8.3357 117.07 120.69 12.508 120.69 121.43 8.3357 121.43 125.02 12.508 125.02 126.41 8.3357 126.41 127.18 33.49 127.18 132.21 12.508 132.21 135.82 20.871 135.82 136.54 12.508 136.54 137.25 8.3357 137.25 140.11 12.508
  1 Comment
Kevin Pollmer
Kevin Pollmer on 31 Mar 2022
Thank you for the answer!
This might also solve the problem. The supervisor of my student research paper wanted to have a clear output of the time intervall and the calculated distance travelled . He mentioned a plot, but a table should be sufficient enough :D

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!