MATLAB: The min and max function return incorrect result!

matlab functionmax/min

Hi, I generate a feature matrix from wavelet dicomposion of an EEG signal, for example with 2×16 double dimensions. But when I want to see max and min for all columns, for some columns, it return 0!!
here is my matrix:
Features = [1227752731.63331, 18338294.3655838, 72667987.4176357, 2710006.87295031, 2623292.81882001, 16791624.0266024, 570620.052920511, 206222.333358212, 1001033.71805223, 16658.1448182973, 43506.1703317381, 143319.583017336, 21259.4058920161, 33646.8754811107, 87870.4592040121, 10139.3064159190
; 373181415.803611, 2184323.98283064, 7124198.60955997, 168359.098887688, 287423.644267531, 1448871.84718216, 42715.7953000498, 30445.2160607579, 100263.257495253, 5559.10902863085, 9485.91790552470, 74748.0071948079, 2814.63617073193, 4522.57176240473, 10081.3836180636, 1715.21296944122];
% As you can see, my 16th column values are:
Features(:,16)
ans =
1.0e+04 *
1.0139
0.1715
% But if I type max(Features), it gets me 0.0000 for column 16th and some other columns as well
max(Features)
ans =
1.0e+09 *
Columns 1 through 10
1.2278 0.0183 0.0727 0.0027 0.0026 0.0168 0.0006 0.0002 0.0010 0.0000
Columns 11 through 16
0.0000 0.0001 0.0000 0.0000 0.0001 0.0000
% But if I type max(Features(:,16)
max(Features(:,16))
ans =
1.0139e+04
So I was wundering what would this happen?!!
Note: I didn't use max or min keywords in any part of my code. I check that with which('max', '-all') command.
Tnx in advance.

Best Answer

  • The default display format short displays arrays with five significant figure precision and a common multiplier for all values in the array (the multiplier is the order of the largest magnitude value). The common multiplier seems to confuse you, so lets have a look at your data. The largest value is 1227752731.63, which has an order of magnitude 9. So all numbers will display with that magnitude and five digits precision, we can visualize this easily:
    ...00001227752731 largest value
    ...****98765***** order of digits to be shown for ALL numbers in that array
    Now lets see when we use only those digits for the value 10139:
    ...****98765***** order of digits to be shown for ALL numbers in that array
    ...00000000010139
    The first five digits, starting from order 9, are 0, 0, 0, 0, 0. The digits marked * are not shown, they are beyond the precision for the specific format that you are using. Note also the implicit infinite leading zeros (I didn't manage to write them all in on this forum, so they are a bit truncated). Note also how this applies to all values in that array, e.g. the fifth element in the first row is displayed as 0.0026, and now it should be clear why:
    ...****98765***** order of digits to be shown for ALL numbers in that array
    ...00000002623292
    If you want to use a different display format, then change it. Probably shortE would give you what you expect:
    >> format short E
    >> max(Features,[],1)
    ans =
    Columns 1 through 8
    1227752731.63 18338294.37 72667987.42 2710006.87 2623292.82 16791624.03 570620.05 206222.33
    Columns 9 through 16
    1001033.72 16658.14 43506.17 143319.58 21259.41 33646.88 87870.46 10139.31
    Note this does NOT have a common multiplier at the top, now every value has its own multipler.