Search code examples
arraysmatlabfunctionargumentscell-array

Pass contents of cell array as individual input arguments to a function in MATLAB


I have a cell array in MATLAB, say A{1}, A{2}, A{3},...., A{561}. I want pass it to a function argument like:

horzcat(A{1}, A{2}, ..., A{561})

Obviously, it is a lethargic way to write all the cells. What is the shortcut way to do it?

I have already tried horzcat(A{1}:A{561}) but it is not working.


Solution

  • Convert your cell array A into a comma-separated list using A{:} and then pass it as a function input argument e.g.

    horzcat(A{:})