arrayfun with scalar expansion

Versione 3.0 (6,3 KB) da Matt J
Version of arrayfun which allows argument arrays to have different sizes, so long as they are compatible for scalar expansion.
1 download
Aggiornato 7 gen 2026

Visualizza la licenza

At the time of this submission, the syntax of arrayfun(),
B = arrayfun(fun,A1,...,An)
requires that all input arrays A1,...,An have the same size (on the CPU, not on the GPU). In this submission, we provide alternatives in which this requirement is relaxed, allowing the input arrays to be of different sizes, so long as they are compatible for scalar expansion. The submission includes two implementations, one which is RAM-conserving (arrayfunLowMem) and one which is liberal with RAM, but somewhat faster (arrayfunHighMem).
A few examples are shown below. Further examples are presented in the Examples tab, with tests of speed performance. Both implementations (arrayfunLowMem and arrayfunHighMem) prove to be considerably faster in these tests than Matlab's native arrayfun command.
>> arrayfunHighMem(@plus, [10,20,30],[4;5])
ans =
14 24 34
15 25 35
>> arrayfunHighMem(@(a,b)[a,b] , [10,20,30],[4;5],'UniformOutput',0)
ans =
2×3 cell array
{[10 4]} {[20 4]} {[30 4]}
{[10 5]} {[20 5]} {[30 5]}

Cita come

Matt J (2026). arrayfun with scalar expansion (https://it.mathworks.com/matlabcentral/fileexchange/182992-arrayfun-with-scalar-expansion), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2024b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Versione Pubblicato Note della release
3.0

Speed performance improvements

2.0.1

Improved Examples.mlx time computation

2.0

Replaced original package with LowMem and HighMem versions.

1.0.0