File Exchange

image thumbnail

Outer Operation

version 1.0.0.0 (707 Bytes) by Murphy O'Brien
e.g. Outer Product, Outer Sum, Outer Equals etc...

2 Downloads

Updated 01 Jun 2007

No License

Calculates resultant matrix when the OPERATOR is applied to all combinations of the elements of vector A and the elements of vector B e.g. the outer product of A and B is outerop(A,B,'*'), the outer sum of A and B is outerop(A,B,'+')

If OPERATOR is omitted '+' is assumed

This function is equivalent to the APL language's circle.dot operation. e.g. in APL Ao.*B is the outer product of A and B % and Ao.+B is the outer sum.

Ideally, it would work on matrices but in practice
I've only ever needed to use it with vectors.

Cite As

Murphy O'Brien (2021). Outer Operation (https://www.mathworks.com/matlabcentral/fileexchange/8370-outer-operation), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (5)

Carl Witthoft

In response to Matthew Doyle's query: take a look at 29428, or at my soon-to-be-published "outer" function :-).

Matthew Dowle

I only had a quick look. Isn't this going to be slow for large vectors. It does "*ones()" which will repeat the vector over and over again in memory. It does this "*ones()" for both vectors. Isn't this innefficient, it will be slow and use too much memory. Does matlab have an efficient outer() function which does a nested for() loop through the vectors, without bloating them in memory first, and then populate the result matrix, which is the only memory required that large. Does such an efficient function exist?

Zeke Cummings

I love outerop and suggest it be part of the next MATLAB release. Murphy told me, " it works with any diadic function e.g. like this outerop(1:5, 6:-1:1, 'max')".

Keith Bonin

Only works on vectors.

urs (us) schwarz

nowadays one could replace the switchyard with this more versatile approach

% start of code
% now, instead of comparing all possible ops

fop=str2func(operator);
y=fop(outera,outerb);

% eg,
fop=str2func('+')
% fop=@plus

profiling both versions shows that there is no penalty in speed between the hand-coded and the function-handle code

just a thought
us

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!