how can i do a multiplication between a column and a row?
Show older comments
when i make a product between a column and a row it says that it is incosistent row / column dimensions
3 Comments
Walter Roberson
on 3 Feb 2022
Are you using the * operator or the .* operator? What is size() of the left vector and size() of the right vector? Which MATLAB release are you using?
Jesus Francisco Serna Monsivais
on 3 Feb 2022
Those are both row vectors. A comma and a space do the same thing in concatenation, e.g., when defining a vector/matrix.
To make a column vector you can use semicolons:
A = [2 3 4];
B = [-2; 1; 3];
A*B
B*A
Accepted Answer
More Answers (1)
The * operator is for algebraic matrix multiplication, also known as inner product. When you take A*B then size(A,2) must be the same as size(B,1) and the result is size(A,1) by size(B,2) . For example,
A=[2;3;4], B=[-2,1,3]
size(A,2) == size(B,1)
C = A*B
[size(A,1), size(B,2)] == size(C)
So if you want to use the * operator between two row vectors of the same length, then you need to transpose one of the two. If you transpose the first of them then the result would be a square matrix; if you transpose the second of them then the result would be a scalar.
If you want to multiply A(1) by B(1) and A(2) by B(2) and so on, then that is not the * operator, it is the .* operator
A=[2,3,4], B=[-2,1,3]
C = A .* B
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!