The min and max function return incorrect result!
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, I generate a feature matrix from wavelet dicomposion of an EEG signal, for example with 2x16 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.
0 Kommentare
Akzeptierte Antwort
Stephen23
am 20 Mai 2020
Bearbeitet: Stephen23
am 24 Mai 2020
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.
Weitere Antworten (1)
Rik
am 20 Mai 2020
You didn't notice the exponent:
max(Features)
ans =
1.0e+09 *
If you want to control how your data shows up in the command window you should use fprintf.
6 Kommentare
Stephen23
am 20 Mai 2020
"Could you please explain how "The value 1.0139e4 printed to five significant figures starting with order 9 figure is 0.0000" in more detail?!"
Lets use a simple example with 654321 and 9.
Now lets print their values using a common multiplier (the order of the largest value) and three significant figures. First we find the three digits at the required orders:
654321
000009
^^^ % three significant digits
So the output is clearly 6.54e5 and 0.00e5. Then you move the common multiplier and display it at the top:
1e5*
6.54 0.00
Siehe auch
Kategorien
Mehr zu Large Files and Big Data finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!