フィルターのクリア

select complex numbers from cell array based on the real part

4 ビュー (過去 30 日間)
Ilias Minas
Ilias Minas 2020 年 6 月 3 日
コメント済み: dpb 2020 年 6 月 3 日
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 件のコメント
Stephen23
Stephen23 2020 年 6 月 3 日
Why are you storing scalar numerics in a cell array?
Ilias Minas
Ilias Minas 2020 年 6 月 3 日
Its the solution of the eigenproblem. I convert it later to matrix.

サインインしてコメントする。

採用された回答

dpb
dpb 2020 年 6 月 3 日
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 件のコメント
Ilias Minas
Ilias Minas 2020 年 6 月 3 日
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 2020 年 6 月 3 日
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.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by