MATLAB Answers


How to multiply the following?

Considering an image I of any size. A mask of size 1X10. How to multiply those two?


a.*b... Most probably it should work

I'm getting error

??? Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles.
Jan Simon
on 10 Sep 2012

You cannot multiply a [MxNx3] array directly by a [1x10] vector. It is not clear what kind of output you expect for such a calculation.

1 Answer

Answer by Titus Edelhofer
on 10 Sep 2012
 Accepted answer


the error indicates what's wrong: your image and your mask have different types (probably your image is e.g. uint8 and your mask is double). If you need your mask to have non integer values (e.g. 2.345), convert your image to double:

dblImage = double(yourImage);

Otherwise you might try to convert your mask to the same integer type as your image (by using uint8, ...).



Jan Simon
on 10 Sep 2012

Please post the relevant part of your code. Without the code and without an exact copy of the error message, we can only guess what's going on.

This is my code. deg0 is 1X10 mask. threshImage is the input Image.

for i=1:10
      deg0(i) = 0.25;
  [rows columns] = size(threshImage);
  for j = 1 : columns
      for i= 1 : 10 : rows
          filtImage0(i,j) = threshImage(i,j).*deg0;


if you do it by loop, you need to index deg0 as well:

filtImage0(i,j) = threshImage(i,j).*deg0(i);


filtImage0(i,j) = threshImage(i,j).*deg0(j);


Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!