diff options
Diffstat (limited to 'SD-VBS/common/matlab/product.m')
| -rwxr-xr-x | SD-VBS/common/matlab/product.m | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/SD-VBS/common/matlab/product.m b/SD-VBS/common/matlab/product.m new file mode 100755 index 0000000..65548b4 --- /dev/null +++ b/SD-VBS/common/matlab/product.m | |||
| @@ -0,0 +1,30 @@ | |||
| 1 | function [matrixOut] = product(matrixIn, direction) | ||
| 2 | |||
| 3 | % Initialize matrices | ||
| 4 | inputDim = size(matrixIn); | ||
| 5 | |||
| 6 | % For input matrix (m,n), we need to multiply horizontally if output matrix | ||
| 7 | %is (m). Else, we multiply vertically. | ||
| 8 | |||
| 9 | %if direction is 1, we multiply vertically. | ||
| 10 | if direction == 1 | ||
| 11 | matrixOut = zeros(1, inputDim(2)); %initialize the output matrix | ||
| 12 | for cols = 1:inputDim(2) | ||
| 13 | val = 1; | ||
| 14 | for rows = 1:inputDim(1) | ||
| 15 | val = matrixIn(rows, cols) * val; | ||
| 16 | end | ||
| 17 | matrixOut(cols) = val; | ||
| 18 | end | ||
| 19 | |||
| 20 | % else multiply horizontally | ||
| 21 | else | ||
| 22 | matrixOut = zeros(inputDim(1), 1); %initialize the output matrix | ||
| 23 | for rows = 1:inputDim(1) | ||
| 24 | val = 1; | ||
| 25 | for cols = 1:inputDim(2) | ||
| 26 | val = matrixIn(rows, cols) * val; | ||
| 27 | end | ||
| 28 | matrixOut(rows) = val; | ||
| 29 | end | ||
| 30 | end \ No newline at end of file | ||
