Be the first to rate this file! 0 Downloads (last 30 days) File Size: 11.79 KB File ID: #23146

matrixfunction

by Pierce

 

28 Feb 2009 (Updated 03 Mar 2009)

summary

| Watch this File

File Information
Description

functions that allow functions to operate on the rows and coloums of matrixs. similiar to arrayfun and bsxfun.
Saves time having to implement for loops or figuring out how to vectorise your code

% matrixfun
% Y = matrixfun(hFunction,A,B,Dim)
%
% Invokes hFunction on the columns of matrices A and B.
% hFunction is a function handle that accepts two vectors.
% hFunction is invoked aCols*bCols times.
% Y is a cell matrix of size([aCols bCols]).
% If Dim is 2, hFunction operates on the rows of matrices A and B.
%
% Example
% A = [1 1 1; 2 2 2; 3 3 3]
% Y = matrixfun(@(X,Y)sum(X-Y),A,A);
% Y = [0] [0] [0]
% [0] [0] [0]
% [0] [0] [0]
%
% Y = matrixfun(@(X,Y)sum(X-Y),A,A,2); % = matrixfun(@(X,Y)sum(X-Y),A.',A.')
% Y = [0] [-3] [-6]
% [3] [ 0] [-3]
% [6] [ 3] [ 0]
%

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
03 Mar 2009 Stephen Lienhard

See also http://www.mathworks.com/matlabcentral/fileexchange/16467 which I am the author of. While it only operates on one matrix, it is generalized to operate over any dimension.

Please login to add a comment or rating.
Updates
03 Mar 2009

 added 3 functions to handle single matrices

Tag Activity for this File
Tag Applied By Date/Time
matrices Pierce 02 Mar 2009 12:35:20
vectors Pierce 02 Mar 2009 12:35:20
for loops Pierce 02 Mar 2009 12:35:20
arrayfun Pierce 02 Mar 2009 12:35:20
matrixfun Pierce 02 Mar 2009 12:35:20
bsxfun Pierce 02 Mar 2009 12:35:20
matrix function Pierce 03 Mar 2009 15:47:47
matrix function Marco 07 Aug 2009 02:49:40

Contact us at files@mathworks.com