Skip to content
Snippets Groups Projects
Commit 953a6e13 authored by Nicola Vigano's avatar Nicola Vigano
Browse files

Maths: fixed reshape error in matrix multiplication

parent 17e77abf
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,23 @@ function C = gtMathsMatrixProduct(A, B) ...@@ -2,10 +2,23 @@ function C = gtMathsMatrixProduct(A, B)
[size_A(1), size_A(2), size_A(3)] = size(A); [size_A(1), size_A(2), size_A(3)] = size(A);
[size_B(1), size_B(2), size_B(3)] = size(B); [size_B(1), size_B(2), size_B(3)] = size(B);
if (size_A(3) ~= size_B(3))
if (all([size_A(3), size_B(3)] ~= 1))
error('gtMathsMatrixProduct:wrong_argument', ...
'The matrix stacks should have either the same number of matrices, or one should be one')
elseif (size_A(3) == 1)
num_out = size_B(3);
else
num_out = size_A(3);
end
else
num_out = size_A(3);
end
A = reshape(A, size_A(1), size_A(2), 1, size_A(3)); A = reshape(A, size_A(1), size_A(2), 1, size_A(3));
B = reshape(B, 1, size_B(1), size_B(2), size_B(3)); B = reshape(B, 1, size_B(1), size_B(2), size_B(3));
C = bsxfun(@times, A, B); C = bsxfun(@times, A, B);
C = sum(C, 2); C = sum(C, 2);
C = reshape(C, size_A(1), size_B(2), size_A(3)); C = reshape(C, size_A(1), size_B(2), num_out);
end end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment