each

iterate cell array contents without clutter
19 descargas
Actualizado 22 nov 2017

Ver licencia

The "each"-utility allows to iterate the contents of a cell array using a for-loop almost like one would do with any numeric or struct array that isn't in cells.
Normally, when using a for loop, the cell array is passed to the loop variable in columns (that are Nx1-cell arrays).

for elem = {'a', 'list', 'of', 'words'}
class(elem) % -> cell
size(elem) % -> 1x1
disp(elem{1}); % need unpack
end

This is inconvenient, when using only row-vector lists of things. One would want the for-loop to directly assign the 1x1-colum-cell's content to the loop variable. Passing the cell through the constructor of the "each"-utility, you can achieve just that.

for elem = each({'a', 'list', 'of', 'words'})
class(elem) % -> char
size(elem) % -> 1xN (length of word)
disp(elem); % need not unpack
end

It also looks very clean, i think.

One restriction is, that "each" will pass out the contents of all n*m 1x1-cells of the original nxm-cell-array one after another, rather than passing a column at a time - there is after all only one variable to receive the result. For clarity, you should therefore only use it with row-vectors.

Under the hood, "each" is a thin class (whos instances are only temporary). It wraps the cell-array containing the data and provides size- and subsref-handlers that suite the way MATLAB internally does for-loops.

Citar como

Robert Rasche (2024). each (https://www.mathworks.com/matlabcentral/fileexchange/65149-each), MATLAB Central File Exchange. Recuperado .

Compatibilidad con la versión de MATLAB
Se creó con R2012b
Compatible con cualquier versión
Compatibilidad con las plataformas
Windows macOS Linux
Categorías
Más información sobre Data Type Identification en Help Center y MATLAB Answers.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Versión Publicado Notas de la versión
1.0.0.0