⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matmul.m

📁 计量工具箱
💻 M
字号:
function out = matmul(x,y)
% PURPOSE: performs matrix multiplication even if matrices
%          are not of the same dimension, but are row or
%          column compatible
%---------------------------------------------------
% USAGE: result = matmul(x,y)
% where:    x,y = two matrices (not of the same dimension
%                 but are row or column compatible)
%---------------------------------------------------
% RETURNS: result = x.*y where x and y are row or column compatible
% --------------------------------------------------

% written by:
% James P. LeSage, Dept of Economics
% Unioutersity of Toledo
% 2801 W. Bancroft St,
% Toledo, OH 43606
% jpl@jpl.econ.utoledo.edu


[rx,cx] = size(x);
[ry,cy] = size(y);

if (cx == cy) & (rx == ry);
  out = x.*y;
elseif (cx == cy) & (rx == 1)
	out = y.*repmat(x,ry,1);
elseif (cx == cy) & (ry == 1)
	out = x.*repmat(y,rx,1);
elseif (rx == ry) & (cx == 1);
	out = y.*repmat(x,1,cy);
elseif (rx == ry) & (cy == 1);
	out = x.*repmat(y,1,cx);
else;
   error('matmul: non-conformable in row or column dimension')
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -