Plotting datapoints with their time distance on x-axis
7 views (last 30 days)
Show older comments
Kevin Pollmer
on 31 Mar 2022
Commented: Kevin Pollmer
on 31 Mar 2022
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;
r_0=0.319;
kmh=15;
figure(1)
plot(t(index_1:index_2-1),Betrag_Ableitung);
hold on
plot(max_XWerte,max_YWerte,'mo');
hold off
k=1;
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);
k=k+3;
else
laenge(k) = abs(max_XWerte(k+1)-max_XWerte(k))*(kmh/3.6);
k=k+2;
end
end
for m=1:length(laenge)
if laenge(m) == 0
laenge(m) = laenge(m-1);
end
end
for f=1:length(laenge)
l_test(f)=100*(2*r_Trommel*asin(laenge(f)/(2*r_Trommel)));
end
x=0:1:length(l_test)-1;
figure(2)
plot(x,l_test)
Thank you in advance!!
0 Comments
Accepted Answer
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)
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!