collapse.m

Removes degenerate portions of a cell array tree.
1.7K Downloads
Updated 21 Feb 2006

No License

%c = collapse(c)
% Takes a recursive cell array as a tree and collapses any branches
% having a fanout of 1. Any elements with fanout of 0 are removed.
%
%Examples:
% collapse({1 2 3}) --> {1 2 3}
% collapse({{1} {2} {{3}}}) --> {1 2 3}
% collapse({1 {2 3}}) --> {1 {2 3}}
% collapse({1 {{} 2 {{}} 3}}) --> {1 {2 3}}
% collapse({{{}}}) --> {}
%
% [matches] = regexp({'abc', 'def', 'fghi'}, '[^f]*f+[^f]*', 'match');
% collapse(matches) --> {'def' 'fghi'}
%

Cite As

Gerald Dalley (2026). collapse.m (https://se.mathworks.com/matlabcentral/fileexchange/10005-collapse-m), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Structures in Help Center and MATLAB Answers
Version Published Release Notes
1.0.0.0

Removed boilerplate copyright.