views:

2116

answers:

4

Hi, i have a small function with 2 vectors

alpha =
     1    1    1    1    1    1    1    1    1

f_uv =
   193  193  194  192  193  193  190  189  191

and i get the error message:

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

when i try to do this:

alphaf_uv = alpha * f_uv'.

The interesting part is, that this error doesnt 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.

+8  A: 

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.

paxdiablo
A: 

Thanks solved.

Red33mer
A: 

Perhaps f_uv is an object with "console value" returned by a .toString() method. In this case you may need to box f_uv as (int).

+4  A: 

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.

MatlabDoug

related questions