0

Suppose I have a matrix:

A = [ a, b, c; d, e, f ]; 

and a vector:

b = [ x; y; z ]; 

What I want is resultant matrix as:

C = [ a*x, b*y, c*z; d*x, e*y, f*z ]; 

How can I do this? Essentially, I want to multiply matrix (dimension: mxn) with a vector (nx1) and get resultant matrix mxn.

As requested in comments (using octave version 3.8.0):

octave> A = [ 1,2,3;4,5,6]; B=[10;20;30]; octave> A*B ans = 140 320 octave> A.*B error: product: nonconformant arguments (op1 is 2x3, op2 is 3x1) octave> bsxfun(@times, A, B) error: bsxfun: nonconformant dimensions: 2x3 and 3x1 
7
  • Did you try multiplying them? Commented Feb 13, 2019 at 7:21
  • b is not a scalar. It is a matrix or a colum vector as you prefer Commented Feb 13, 2019 at 7:36
  • @matzeri fixed typo. Commented Feb 13, 2019 at 9:35
  • Please see the documentation of .*. If you're using MATLAB ≤ R2016a, you will need bsxfun. In Octave and MATLAB ≥ R2016b, you can directly use .* (after adjusting the dimensions) Commented Feb 13, 2019 at 9:38
  • 1
    ' is complex conjugate transpose. You should be using simple transpose .' here because it is transpose that you're meant to take. Andy has already posted it. You can go ahead with it. Commented Feb 13, 2019 at 9:53

1 Answer 1

1
A = [ 1,2,3;4,5,6]; B = [10;100;1000]; A.*B.' ans = 10 200 3000 40 500 6000 
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for the answer. I didn't notice your answer before my comment to the question. I am waiting for @SardarUsama 's input before I mark your answer as accepted answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.