Subtraction of two single-precision arrays reuslts in an integer (?) array
조회 수: 2 (최근 30일)
이전 댓글 표시
I have two 512x512 single-precision arrays (frame_1 and frame_2). Typing the name of either of these in the console shows the block of expected 5-digit numbers: 2.1799, -1.1602, 2.7134, 0.6899, ...
When I try to take the difference (frame_diff = frame_2 - frame_1), the displayed frame_diff array now shows as all integers, even though Matlab claims it's also a single (as it should be!). I thought it was just a console display issue, but when I try options such as format shortEng, the frame_diff numbers indeed seem to be integers (or at least rounded floats!).
What gives? I found nothing in the Matlab array subtraction documentation that would explain what's happening here. The same thing happens with minus(frame_1, frame_2), by the way.
댓글 수: 4
Stephen23
2018년 10월 2일
"the displayed frame_diff array now shows as all integers, even though Matlab claims it's also a single "
There is no contradiction here: some display formats do not show trailing zeros, even for floating point numbers. Try it yourself:
>> format short
>> single(pi)
ans =
3.1416
>> single(3)
ans =
3
>> format shorteng
>> single(pi)
ans =
3.1416e+000
>> single(3)
ans =
3.0000e+000
채택된 답변
TAB
2018년 10월 2일
Values in your arrays frame_1 & frame_2 are such that, difference is always a whole number (fraction part is 0). So they appear as integer.
For example:
frame_1(1,1) --> -0.8467
frame_2(1,1) --> 3.1533
frame_1(1,1) - frame_2(1,1) --> -4
frame_1(1,2) --> -5.9399
frame_2(1,2) --> -0.9399
frame_1(1,2) - frame_2(1,2) --> -5
frame_1(1,3) --> 6.8799
frame_2(1,3) --> -4.1201
frame_1(1,3) - frame_2(1,3) --> 11
댓글 수: 3
dpb
2018년 10월 2일
It just looks funny for elements like the first where have to add owing to sign of both being <0 and it's not visual without thinking of the actual operation as in the case of the second.
Clearly the two files were closely linked somehow in whatever it was that generated the values but the symptom is real given the data.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!