File Exchange

image thumbnail


version 1.1 (1.78 KB) by

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



View License

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

Comments and Ratings (4)


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.


Jeremy (view profile)

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


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.


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.



fixed some typos in the example

MATLAB Release
MATLAB 7.11 (R2010b)
Tags Add Tags

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

» Watch video