MATLAB: How to get the min,max, and avg of velocity while showing at what time that I got those values

maxmeanmintext file

So far I got to this point and just cant figure out how to get the time that each of these values are at and display them. I really appreciate any help!
clear;
clc;
veldata = dlmread('veldata.txt',' ');
time = veldata(:,1);
velocity = veldata(:,2);
[min_velocity,2] = min(velocity);
[max_velocity,2] = max(velocity);
[avg_velocity, 2] = mean(velocity);

Best Answer

I can’t run your code, but you can take advantage of the max and min functions also returning the index of the vector at those values:
[min_velocity,minidx] = min(velocity);
[max_velocity,maxidx] = max(velocity);
avg_velocity = mean(velocity);
avgidx = find(velocity <= avg_velocity,1,'last');
Since the mean may not equal any element in the vector, getting the last element less than or equal to the mean is likely as good as it gets.
To get the times at those values, reference them by index:
t_minv = time(minidx);
t_maxv = time(maxidx);
t_avgv = time(avgidx);