1

Is there any simple way to apply a function Foo to multiple arrays (matrices) A,B,C, besides creating a bigger array?

Essentially I want something similar to "map" in Python, like:

L = [A, B, C]
map(foo, L)

Let's assume to cases, 1. the function Foo is applied component-wise, does not change the dimension of the matrix, for example, log(), exp(). 2. Function is a general function,working on the whole matrix, for example, removerows().

1
  • 1
    See my answer to the linked question. The cellfun function may do what you want. Commented Mar 2, 2013 at 17:04

2 Answers 2

1

There is no built in analogue to 'map' in MATLAB by default. However, you could always write the functionality on your own; that has been done here. Put in in your MATLAB bin and you should be ready to go.

If you want your code to be portable across systems though, I'd recommend simple looping.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use varargin and varargout to create a function that takes an arbitrary number of inputs, and produces an arbitrary number of outputs.

So then you would be able to write:

[D, E, F] = map(foo, A, B, C);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.