File Exchange

image thumbnail

MergeCell

version 1.1.0.0 (1.78 KB) by Diederick
Merges contents of multiple cell arrays into one big cell array, with expansion

1 Download

Updated 02 Feb 2012

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

Cite As

Diederick (2020). MergeCell (https://www.mathworks.com/matlabcentral/fileexchange/29866-mergecell), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Diederick

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

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

Diederick

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

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.

Updates

1.1.0.0

fixed some typos in the example

MATLAB Release Compatibility
Created with R2010b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags
Acknowledgements

Inspired: Yahoo! Finance Data Loader