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

New to MATLAB?

MatLab command that will return a matrix that contains the product of every element in two vectors of any length

Asked by marie

marie (view profile)

on 30 Nov 2012
Accepted Answer by bym

bym (view profile)

For example

V1 = [10, 20, 30]  
V2 = [2, 3, 6]  

and the return should be something like

ANS = [20,  40,  60; 
       30,  60,  90; 
       60, 120, 180]

I tried to do v1 .* v2 and the return is something like ans= 20 60 180 which is not what I want... any suggestion? thank you

0 Comments

marie

marie (view profile)

Tags

Products

No products are associated with this question.

2 Answers

Answer by bym

bym (view profile)

on 30 Nov 2012
Accepted answer
V1.'*V2
ans =
      20    30    60
      40    60   120
      60    90   180

0 Comments

bym

bym (view profile)

Answer by Walter Roberson

Walter Roberson (view profile)

on 30 Nov 2012
kron(V1.', V2)

or

bsxfun(@times, V1.', V2)

0 Comments

Walter Roberson

Walter Roberson (view profile)

Contact us