Code covered by the BSD License  

Highlights from
MergeCell

2.0

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

MergeCell

by

 

31 Dec 2010 (Updated )

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

| Watch this File

File Information
Description

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

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.

16 Mar 2011 Jeremy

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

16 Mar 2011 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.

15 Mar 2011 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
02 Feb 2012

fixed some typos in the example

Contact us