MATLAB: How to find component of a max value

max/min

Hello! My code is where I prompt the user to enter in a vector for height, diameter, and specific gravity of a cone. From there I find the volume, mass, and max/min of mass. I want to know how to output the height of the maximum mass. Example: Ht=[1 2 3 4] Diam=[1 2 3 4] Vol=[…,…,…,…] (Random numbers) Mass=[1 2 3 4] maxmass=max(Mass) Ht_maxmass=???

Best Answer

Just get the second output from max, which is the index of the maximum value:
[maxmass,idx] = max(Mass)
Ht_maxmass = Ht(idx)