5.0

5.0 | 1 rating Rate this file 21 Downloads (last 30 days) File Size: 1.29 KB File ID: #27009

Flatten nested cell arrays

by Manu Raghavan

 

18 Mar 2010

Linearize a cell array tree structure

| Watch this File

File Information
Description

 C1 = flatten({{1 {2 3}} {4 5} 6})
 C2 = flatten({{'a' {'b','c'}} {'d' 'e'} 'f'})
 
% Outputs:
 C1 =
     [1] [2] [3] [4] [5] [6]
 C2 =
     'a' 'b' 'c' 'd' 'e' 'f'

MATLAB release MATLAB 7.10 (2010a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
23 Jul 2010 Manu Raghavan

You can use this function to flatten the output from Bloomberg's unordered BLP interface in the Datafeed Toolbox.

26 Jul 2010 Richie Cotton  
20 May 2011 David Goldsmith

Has anyone used this w/ struct2cell to flatten nested structs? Any surprises/non-intuitive behaviors observed?

20 May 2011 David Goldsmith

Never mind, just answered my own ?: you lose all the field keys! Plus, struct2cell isn't recursive, so it only flattens the top of the tree. Still, it gives me something to start from. If I can write something that works robustly, I'll post it.

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
flatten cell linearize Andrei Palvinski 22 Jul 2010 14:38:10
flatten Manu Raghavan 23 Jul 2010 10:50:14
cell Manu Raghavan 23 Jul 2010 10:50:15
linearize Manu Raghavan 23 Jul 2010 10:50:18
blp Manu Raghavan 23 Jul 2010 10:50:20
bloomberg Manu Raghavan 23 Jul 2010 10:50:23
reorder Manu Raghavan 23 Jul 2010 10:50:26
bloomberg Joao 26 Oct 2011 11:06:28

Contact us at files@mathworks.com