0

some function has arbitrary number of input and output. Lets look at ndgrid for example: you can give N inputs, and get N outputs.

v={1:10,2:20,3:30...}
[d0,d1,...]=ndgrid(v{:});

is there's anyway to get all outputs into a cell array, e.g.

[d{:}]=ndgrid(v{:});
Mercury
  • 1,886
  • 5
  • 25
  • 44
  • 2
    Possible duplicate of [How to pass multiple output from function into cell array](https://stackoverflow.com/questions/15523851/how-to-pass-multiple-output-from-function-into-cell-array) – Cris Luengo Jun 27 '18 at 16:29
  • Almost. In this case, the number of output arguments is unknown – Mercury Jun 28 '18 at 14:18
  • If the number of outputs is unknown, this is not possible. Your answer assumes a given number of outputs. Your answer is essentially the same as the answer in the linked question. Replace `6` there with `length(v)` here. – Cris Luengo Jun 28 '18 at 14:23

1 Answers1

0

for future reference, yes:

v={1:10,2:20,3:30...}
d=cell(length(v),1);
[d{:}]=ndgrid(v{:});
Mercury
  • 1,886
  • 5
  • 25
  • 44
  • This assumes the number of inputs is the same as the number of outputs... Might want to initialise `d` to be a size independent of `v` – Wolfie Jun 27 '18 at 17:11