Numeric types error when multiplying two 2 vectors in MATLAB

14,827

Solution 1

Assuming they're both integer matrices to begin with, f_uv' may not be.

Try:

alphaf_uv = double(alpha) * double(f_uv')

and let us know if it still occurs.

You may need to turn alphaf_uv back into an integer type afterwards, depending on your needs.

Solution 2

The big clue here is this:

alpha is defined by me and f_uv is obtained from some pixels in a png image.

This heavily implies that the f_uv data is coming in as uint8. The WHOS command will verify. When you define this at the command line, the vectors will be Double by default. That is why you are seeing the difference in behavior between "identical" matrices.

Share:
14,827
Red33mer
Author by

Red33mer

About who?

Updated on August 05, 2022

Comments

  • Red33mer
    Red33mer over 1 year

    I have these 2 vectors:

    alpha =
         1    1    1    1    1    1    1    1    1
    
    f_uv =
       193  193  194  192  193  193  190  189  191
    

    And when I do this:

    alphaf_uv = alpha * f_uv'
    

    I get the error message:

    "??? Error using ==> mtimes
    Integers can only be combined with integers of the same class, or scalar doubles." 
    

    The interesting part is that this error doesn't appear if I define the same vectors in the console and try the multiplication there.

    alpha is defined by me and f_uv is obtained from some pixels in a PNG image.

  • user481610
    user481610 about 10 years
    Quick question by using double will this affect accuracy? i.e will I go from say 0.159 to double(0.159) = 0.16?