MATLAB: Select complex numbers from cell array based on the real part

cell arrayscomplex numberimaginary partreal part

Hi all,
I have a 7D cell array with complex numbers.
I want to keep the complex number with the highest real part, of all the values of the 3rd parameter (1:15).
For example in this case i want only the val(:,:,14,1,1,1,1) which has the highest real part.
I tried to do it using the following command
maxVal = max(cell2mat(my_array),[],3);
However, it keeps the complex number with higher imaginary part. In this case
val(:,:,15,1,1,1,1)
Any idea of how can i do this?
Thank you

Best Answer

Well, if you want the max() of the real part, then you'll have to limit to only looking at the real part -- max() for complex returns max(abs())
tmp=squeeze(cell2mat(my_array));
[maxRealVal,imxR] = max(real(tmp));
maxVal=tmp(imxR);