View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from

2.0 | 1 rating Rate this file 3 Downloads (last 30 days) File Size: 1.78 KB File ID: #29866 Version: 1.1



Diederick (view profile)


31 Dec 2010 (Updated )

Merges contents of multiple cell arrays into one big cell array, with expansion

| Watch this File

File Information

MergeCell takes any number of cell vectors (contain the same datatype) and concatenates their contents into one big cellvector
Any signleton inputs are expanded as needed, these inputs can be 1x1 cells or the contained datatype itself

Example: To add some information about fit to plot legend, we'd wan't to append information about the fit to the line labels:

linelbls = {'line a','line b','line c'};
slope = [.9 1 4.2];
slopetxt= arrayfun(@(x) sprintf('%.3f',x),slope,'UniformOutput',false);

leglbls = MergeCell(linelbls,', slope: ',slopetxt);
% leglbls = MergeCell(linelbls,{', slope: '},slopetxt); would be equivalent

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
17 Mar 2011 Diederick

Diederick (view profile)

Hi Jeremy,

An example of a usagecase that frequently comes up for me is creating legends in plots. For instance, if you fit a model to some data, it might be nice to also put some information about the fit quality in the legend. An example of that is given in the description at the top of this page.

Comment only
16 Mar 2011 Jeremy

Jeremy (view profile)

Thanks for the info Diedrick. Can you give me an example of when you'd use that?

Comment only
16 Mar 2011 Diederick

Diederick (view profile)

Hi Jeremy, that would be a totally different function (if I understand you correctly, in your output the cells at out(11:100,2) would be empty), this is a function for merging cells, appending the contents in different cells to give you one big cell.

Comment only
15 Mar 2011 Jeremy

Jeremy (view profile)

It would be nice if this function could take, say, a 10x1 cell array and a 100x1 cell array and combine them into a 100x2 cell array. That's what I would have expected from the title and description.

02 Feb 2012 1.1

fixed some typos in the example

Contact us