Error of number types when multiplying two vectors in MATLAB

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 an 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 does not appear if I define the same vectors in the console and try to multiply it.

alpha determined by me, and f_uv obtained from some pixels in the PNG image.

+7
math vector matlab
source share
3 answers

Assuming that for starters they are integer matrices, f_uv' may not be.

Try:

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

and let us know if this is still happening.

You may need to re-enable alphaf_uv back into the integer type, depending on your needs.

+16
source share

The big clue here is this:

alpha is determined by me, and f_uv is obtained from some pixels in the png image.

This pretty much means that f_uv data comes in uint8. The WHOS command will verify. When you define this on the command line, by default the vectors will be double. This is why you see the difference in behavior between β€œidentical” matrices.

+5
source share

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

0
source share

All Articles