Converting a complex number into a single value

조회 수: 7 (최근 30일)
NC
NC 2018년 6월 12일
댓글: Rik 2018년 6월 13일
I have got a matrix of complex values and I want to sort the highest 10 values from it. For this I got the modulus of the complex values and the sorted them. But the values I get after applying modulus change from time to time. How to solve this to get a consistent value? I'm using Matlab IDE.
Code segment used.
realPeriodicityMap = abs(periodicitymap);
disp(realPeriodicityMap);
periodicitymapRow = reshape(realPeriodicityMap, 1, []);
Changes in values are shown below. Instance 1 values:
0.0040 0.0047 0.0014 0.0067 0.0040 0.0023 0.0030
0.0054 0.0040 0.0016 0.0040 0.0078 0.0087 0.0057
0.0054 0.0044 0.0068 0.0040 0.0048 0.0023 0.0012
0.0061 0.0040 0.0032 0.0002 0.0055 0.0055 0.0045
Instance 2 values:
0.0046 0.0045 0.0016 0.0067 0.0037 0.0021 0.0027
0.0057 0.0043 0.0018 0.0044 0.0077 0.0085 0.0051
0.0091 0.0054 0.0051 0.0070 0.0042 0.0051 0.0018
0.0062 0.0038 0.0034 0.0004 0.0056 0.0053 0.0043
  댓글 수: 4
NC
NC 2018년 6월 13일
Yes, same input gives different outputs. I tried your code and it sorts 10 values successfully. But the changes in values is still there.
Rik
Rik 2018년 6월 13일
So running the exact same code produces 2 different results, without any other code being run in between? That would mean the code below would result in false:
sorted=sort(abs(realPeriodicityMap),'descend');
A=sorted(find(sorted, 10));%get top 10 values
sorted=sort(abs(realPeriodicityMap),'descend');
B=sorted(find(sorted, 10));
isequal(A,B)
Can you confirm this?
Are you also sure you didn't make a typo interchanging periodicitymap and realPeriodicityMap? And do you have any m-lint warnings in that piece of code?

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by