Borrar filtros
Borrar filtros

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

8 visualizaciones (últimos 30 días)
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);

Respuesta aceptada

Star Strider
Star Strider el 2 de Nov. de 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);

Más respuestas (0)

Categorías

Más información sobre Systems of Nonlinear Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by