Why can't I multiply two arrays using the '*' operator?
29 次查看(过去 30 天)
显示 更早的评论
Why is it necessary to use the .* operator to multiply two arrays of the same size? For example, if I have array1 = [1,2,3] and array2 [4,5,6] which both have size of 3; why is it not possible to simply use '*'?
0 个评论
采纳的回答
Star Strider
2018-10-20
Because the dot operator does element-wise multiplication (and division and exponentiation). These are termed array operations in MATLAB.
If you do not use the dot operator, you are using standard linear algebra matrix operations, and those require that you follow the rules for array operations from linear algebra.
array1 = [1,2,3];
array2 = [4,5,6];
Result1 = array1' * array2; % 3x3 Matrix (Matrix Multiplication)
Result2 = array1 * array2'; % Scalar (Dot Product)
Result3 = array1 .* array2; % 1x3 (Element-Wise Multiplication)
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!