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!