Why do I receive different results when applying MEDIAN or NANMEDIAN to my matrix, vs. a single column, in MATLAB 7.13 (R2011b)?
2 ビュー (過去 30 日間)
古いコメントを表示
I have the following data:
A = [...
1+1j 6 ; ...
3-1j -4 ; ...
5-1j 2 ]
c = A(:,2)
When I apply MEDIAN to the matrix 'A', I receive -4 for the second column. However, when I apply MEDIAN to the column 'c', I receive 2. This also occurs with NANMEDIAN.
採用された回答
MathWorks Support Team
2012 年 2 月 16 日
The main difference between the two data arrays is that the matrix 'A' is complex, whereas the column 'c' is purely real.
MEDIAN and NANMEDIAN both sort the values in the input data. When the data class is complex, the sort operation uses the absolute value of the data. In that case, the comparison of negative and positive real numbers will depend on whether the absolute values of the negative numbers are larger than the absolute values of the positive ones. This is the cause of the discrepancy you are seeing.
You can try either of the following options:
1. Segment the data into two parts with each only containing real or complex entries using ISREAL. Then apply your median finding operation to each part separately, to obtain the corresponding results.
2. Create your own version of these functions that can handle a mixture of real and complex numbers by modifying the original functions (after saving backup copies of the original functions).
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Shifting and Sorting Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!