1

I want to input arguments to an octave function as a cell array:

function x = myfunc(a_string, an_int)
  printf("a string: %s\n", a_string);
  printf("an int: %d\n", an_int);
end

myfunc("a", 1);
b = {"a", 1};
myfunc(b); % should do the same thing as myfunc("a", 1)

Is there any way to do this easily?

Evan Gunter
  • 69
  • 1
  • 5

1 Answers1

2

You need to use {:} indexing to expand the contents of the cell array out into multiple inputs to your function. The {:} indexing creates a comma separated list which behaves just as multiple inputs.

myfunc(b{:})
Suever
  • 64,497
  • 14
  • 82
  • 101