www.gusucode.com > matlab 案例源码 matlab代码程序 > matlab/DotProductofMatricesExample.m

    %% Dot Product of Matrices  

%% 
% Create two matrices. 
A = [1 2 3;4 5 6;7 8 9];
B = [9 8 7;6 5 4;3 2 1];  

%% 
% Find the dot product of |A| and |B|. 
C = dot(A,B) 

%%
% The result, |C|, contains three separate dot products. |dot| treats the
% columns of |A| and |B| as vectors and calculates the dot product of
% corresponding columns. So, for example, |C(1) = 54| is the dot product of
% |A(:,1)| with |B(:,1)|.

%% 
% Find the dot product of |A| and |B|, treating the _rows_ as vectors.
D = dot(A,B,2) 

%%
% In this case, |D(1) = 46| is the dot product of |A(1,:)| with |B(1,:)|.