Matlab: Vector product, multiply 2 column matrices, "element-wise" multiplication

If we have 2 column matrices A, B.
>>A = [10;20;30]
A =
10
20
30

>> B = [1;2;3]
B =
1
2
3

>> A+B
ans =
11
22
33

>> A*B
??? Error using ==> mtimes
Inner matrix dimensions must agree.

In order to perform "element-wise" operations, we have to use ".", so for multiplication ".*", division "./"

>> A.*B
ans =
10
40
90

>> A./B
ans =
10
10
10

No comments:

Post a Comment

Python contextlib for Timing Python code

If you've ever found yourself needing to measure the execution time of specific portions of your Python code, the `contextlib` module o...