How can I multiply columns of a matrix and obtain a column vector.
Example: A =
1 1 4
3 2 2
2 1 1
4 1 1
Expected output: C =
4
12
2
4
Any ideas without for?
You can simply use the inbuilt prod
function as prod(A,2)
or prod(A')'
.
For example:
>>
A = [
1 1 4
3 2 2
2 1 1
4 1 1
];
Now:
>> prod(A,2)
ans =
4
12
2
4
For more details, try help prod
.