Mario Krenn
Mario Krenn

Reputation: 223

MATLAB: Combine two cells of arrays

I have two cells which contains arrays, and I want to combine them:

A={[1 2 3],[],[10]};
B={[],[33,2,1,3,1],[3,4,1]};

I want C={[1 2 3],[33,2,1,3,1],[10,3,4,1]}.

Is there a nice method that does not involve a for-loop over all elements?

Upvotes: 0

Views: 132

Answers (1)

Suever
Suever

Reputation: 65430

You can use cellfun to go through and horizontally concatenate all of the cell array entries.

C = cellfun(@(a,b)[a b], A, B, 'Uniform', 0);

Upvotes: 2

Related Questions