Asked by Paul Fini
on 1 Oct 2018

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.

Answer by TAB
on 2 Oct 2018

Accepted Answer

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

John D'Errico
on 2 Oct 2018

fdiff = frame_1 - frame_2;

any(any(fdiff ~= round(fdiff)))

ans =

logical

0

So there are no elements where the difference is not an exact integer.

dpb
on 2 Oct 2018

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.

Paul Fini
on 2 Oct 2018

Thanks, TAB! This hadn't occurred to me, but it may be due to the nature of these two arrays. This gives me some peace of mind that it's the data itself and not some funky Matlab number typing that I didn't understand (that's happened before!).

I'll do some checking to verify on my end and follow up with any questions if needed.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## John D'Errico (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/421700-subtraction-of-two-single-precision-arrays-reuslts-in-an-integer-array#comment_616629

## dpb (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/421700-subtraction-of-two-single-precision-arrays-reuslts-in-an-integer-array#comment_616631

## Paul Fini (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/421700-subtraction-of-two-single-precision-arrays-reuslts-in-an-integer-array#comment_616633

## Stephen Cobeldick (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/421700-subtraction-of-two-single-precision-arrays-reuslts-in-an-integer-array#comment_616867

Sign in to comment.