MATLAB: How to find the index of the maximum Value in a given subintervall in the normal array

findindexMATLABmax

Hi community,
first time asking a question here. I am currently dealing with task involving this problem:
For simplification, lets say, I have two corresponding arrays:
Current_array = [0 1 2 3 4 5];
Voltage_array = [1 2 3 4 5 6];
I want to find the index of the maximum Value in the current_array, but only in the regime, where the corresponding Voltage_array is smaller than 2:
[~,index] = max ( (Current_array (Voltage_array > 2) ) );
My output index would be 4, since the largest value of my subarray (Current_array (Voltage_array > 2) ) = [3 4 5 6] is at position 4.
But what I really want is to find the index of that maximum value in my Current_array, which would be index = 6.
Is there an elegent way to solve this?

Best Answer

[~,index]=max(Current_array.*(Voltage_array>2));