フィルターのクリア

Behavior of "unique" with mixed complex numbers

7 ビュー (過去 30 日間)
Joel Miller
Joel Miller 2020 年 12 月 4 日
コメント済み: Bruno Luong 2020 年 12 月 11 日
I have a large set of complex number that I want to map to an integer grid on the complex plane, removing redundant values. A small subset of the data looks like:
Atest=[-12.9753 - 0.8003i;
-12.9938 - 0.4003i;
-13.0000 + 0.0000i;
-12.9938 + 0.4003i;
12.9938 + 0.4003i;
13.0000 + 0.0000i;
12.9938 - 0.4003i;];
I use round to map to the grid:
Around=round(Atest)
Around =
-13.0000 - 1.0000i
-13.0000 + 0.0000i
-13.0000 + 0.0000i
-13.0000 + 0.0000i
13.0000 + 0.0000i
13.0000 + 0.0000i
13.0000 + 0.0000i
I then use unique to remove the redundant values:
Aunique=unique(Around,'stable')
Aunique =
-13.0000 - 1.0000i
-13.0000 + 0.0000i
-13.0000 + 0.0000i
13.0000 + 0.0000i
Clearly, the result is not unique: the value -13 appears twice. If I apply unique to just the las 6 values of Around (the real values) I obtain the expected results:
Aunique=unique(Around(2:end),'stable')
Aunique =
-13
13
I would appreciate any suggestions for getting the unique values of an array with mixed real and complex values.
  11 件のコメント
Bruno Luong
Bruno Luong 2020 年 12 月 7 日
Here is the reply from tech support
"Thank you for your inquiry and provided clear reproduction examples. It does appear as though this is a bug with the unique function executed on rounded complex arrays. The Development team has been informed of this bug and will investigate further.
Given the information above, I will close this case as 'Bug/Enhancement Submitted'. From a Technical Support perspective the case is now closed. From a Development standpoint, on the other hand, the matter is still open. It is being investigated and will be considered for a future Release or Update. Should this bug be fixed, you will be personally notified via email. Then, the status of this service request will be automatically changed to 'Bug Fixed/Enhancement Complete'. "
So obviously it's abug and they will fix it in future release.
Bruno Luong
Bruno Luong 2020 年 12 月 11 日
Another mail from tech:
"I just wanted to offer you a follow up email regarding a workaround for your use case. If you add complex(0)to 'Around', then call unique, it will give the right answer. For example:"
A = [-12.9753 - 0.8003i; -12.9938 - 0.4003i; -12.9938 + 0.4003i; 12.9938 + 0.4003i];
B = round(A) + complex(0);
C = unique(B);
But we already knew this solution from the cross-thread of atan2 and sign bit.

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

採用された回答

Marco Riani
Marco Riani 2020 年 12 月 4 日
Please let me know if I understood correctly your qestion
Atest=[-12.9753 - 0.8003i;
-12.9938 - 0.4003i;
-13.0000 + 0.0000i;
-12.9938 + 0.4003i;
12.9938 + 0.4003i;
13.0000 + 0.0000i;
12.9938 - 0.4003i;];
Around=round(Atest);
A=[real(Around) imag(Around)];
unique(A,'rows')
ans =
-13 -1
-13 0
13 0
  2 件のコメント
Joel Miller
Joel Miller 2020 年 12 月 4 日
Marco, thank you, this works as I had hoped. I would be interested to know why the round function appears to be outputting integers for the real and imaginary components, but they are treated as floating point when combined into a complex number.
Marco Riani
Marco Riani 2020 年 12 月 4 日

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by