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

7 次查看(过去 30 天)
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);

采纳的回答

Star Strider
Star Strider 2014-11-2
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);

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Systems of Nonlinear Equations 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by