In Simulink I have a signal that is a 1-D array. I need to get the index associated with the first maximum (or minimum) value in the array. In MATLAB, that's simply this:
>> [val,idx] = max([2 3 6 8 4 7 8 4 5 6])
where idx is the item I'm looking for.
Trying to do that in Simulink seems to be much less straightforward. The MinMax block does not offer an option to output the index of the first maximum value.
Coupling a MinMax with a Find Nonzero Elements blocks as in the suggestion on this page does do the trick, but it comes with the problem that the output of the find block is a variable-sized signal. I don't want it to be a variable sized signal; I just want the first index.
One could also use a MATLAB Function block and use the MATLAB min or max function as above, but MATLAB Function blocks take obnoxiously long to compile and often generate code with a lot of gunky overhead.
Is there not a simple, clean, cheap way to get the first max index?