Effacer les filtres
Effacer les filtres

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

7 vues (au cours des 30 derniers jours)
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);

Réponse acceptée

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

Plus de réponses (0)

Catégories

En savoir plus sur Systems of Nonlinear Equations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by