select complex numbers from cell array based on the real part

4 visualizzazioni (ultimi 30 giorni)
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
  2 Commenti
Stephen23
Stephen23 il 3 Giu 2020
Why are you storing scalar numerics in a cell array?
Ilias Minas
Ilias Minas il 3 Giu 2020
Its the solution of the eigenproblem. I convert it later to matrix.

Accedi per commentare.

Risposta accettata

dpb
dpb il 3 Giu 2020
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);
  4 Commenti
Ilias Minas
Ilias Minas il 3 Giu 2020
The problem with the maxVal is that keeps the complex number with higher abs value either its real or imaginary.
It returns complex number but in the example showed above i want the corresponding imaginary part of the highest real part, and it returns the complex number with the higher value of imaginary part.
The one that i want to extract is
val(:,:,14,1,1,1,1)
[7.5646e+02 + 1.4443e+03i]
and it gives me back
val(:,:,15,1,1,1,1) =
{[3.4384e+01 + 1.6918e+03i]}
which has the absolute highest imaginary part.
dpb
dpb il 3 Giu 2020
With your code, yes...with mine, no. Attach some readable data so don't have to make it up (don't use images, select/past text instead).
Well, what the ... poke, poke, ...
val=complex([0.21,0.28,0.34,745.4,34.3],[1460.9,1460.9,1460.9,1444.3,1691.9]); % approx subset sample data
% find return value with maximum real part...
[vMxR,iMxR]=max(real(val)); % return location
% display result
>> val(iMxR)
ans =
7.4540e+02 + 1.4443e+03i
>> imag(val(iMxR))
ans =
1.4443e+03
>>
by contrast,
>> abs(val)
ans =
1.0e+03 *
1.4609 1.4609 1.4609 1.6253 1.6922
>> [~,imx]=max(abs(val))
imx =
5
>> [~,imx]=max((val))
imx =
5
>>
which shows since the real part is stlll small(ish) in comparison, the larger imaginary component dominates in the abs() value which is what max() returns for complex variable.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by