Subtraction of two single-precision arrays reuslts in an integer (?) array
Show older comments
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 Comments
John D'Errico
on 1 Oct 2018
If you want serious help, then you need to post a .mat file that contains the two arrays. Otherwise anybody would just be making wild guesses as to what you have. Attach a .mat file to your question or to a comment.
dpb
on 1 Oct 2018
And, of course, if all elements of the two when subtracted are apparently integer, don't need all 512x512 but just a small subset will suffice just as well.
Paul Fini
on 1 Oct 2018
Stephen23
on 2 Oct 2018
"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
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!