If you are using *, than it is a matrix multiplication and the size of your matrices must be compatible.
If you want to multiply element per element, uses .* .
Examples:
a = [1 2 3];
b = [1 2 3; ...
4 5 6; ...
7 8 9];
c = [9 8 7; ...
6 5 4; ...
3 2 1];
a * b
a * c
a .* b
b .* c
1 Comment
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/496061-i-keep-getting-error-matrix-dimensions-must-agree#comment_776917
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/496061-i-keep-getting-error-matrix-dimensions-must-agree#comment_776917
Sign in to comment.