Effacer les filtres
Effacer les filtres

Find biggest number of variables and also it´s ID-number

2 vues (au cours des 30 derniers jours)
Ion
Ion le 22 Fév 2013
Hello!
I have 6 variables in Simulink. They are:
Car1_Speed, Car2_Speed, Car3_Speed, Car1_ID, Car2_ID, and Car3_ID
I´m comparing the car speeds. I use the max function to find the fastest car at any time. I would like to also know which car is the fastest but I don´t know the way to show also the Carx_ID for the fastest car. Is it possible with Simulink blocks or with some user defined Matlab-function?
How can I do this most efficiently?
Thank you in advance!

Réponses (2)

Sean de Wolski
Sean de Wolski le 22 Fév 2013
First: FAQ
Second:
doc max
You'll see
[maxValue, index] = max(...)

Image Analyst
Image Analyst le 22 Fév 2013
Try this (untested):
[maxSpeed, indexOfFastest] = max([Car1_Speed, Car2_Speed, Car3_Speed])
if indexOfFastest == 1
fastestCarID = Car1_ID;
elseif indexOfFastest == 2
fastestCarID = Car2_ID;
else
fastestCarID = Car3_ID;
end

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by