lil-wolf
lil-wolf

Reputation: 382

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.

Upvotes: 5

Views: 746

Answers (1)

Sardar Usama
Sardar Usama

Reputation: 19689

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{:})

Upvotes: 6

Related Questions