1
votes

Given a multiple input matlab function

out=f(in1, in2) 

I would like to write a second function g which generates the inputs for f, e.g.

[in1, in2]=g(in)

so that I can call something like:

out=f(g(in))

I have tried writing g as a single output function which stores in1 and in2 in a cell array, so that i can feed the output of g to f using the colon operator:

in_c=g(in);
out=f(in_c{:})

but I was looking for a one-line solution, which seems not possible to achieve this way as I read in:

Is it possible to apply colon operator on an expression in MATLAB?

Is there any other way to do this?

1
This is not possible in Matlab. The best you could do is to have f take a cell array as input, and g return a cell array as output.Chris Taylor

1 Answers

0
votes

As discussed recently, this is not possible in Matlab.

However, if you do not want to re-write your function g(x,y) to return a cell array, you can still do everything in two lines:

[in4f{1}, in4f{2}] = g(in);
out = f(in4f{:});

As an aside: Unless you're really hurting for memory, it doesn't make a lot of sense to try and force one-line statements everywhere by avoiding temporary variables. Sure, you can make your code look like CrazyPerl, but in the long run, you'll be glad for the added readability.