disperse

Assign elements of an input array to individual output variables with a single function call.
1,2K download
Aggiornato 30 nov 2011

Visualizza la licenza

Nota dell'editore: This file was selected as MATLAB Central Pick of the Week

Oftentimes when using Matlab we find ourselves having to perform a series of repetitive assignments from some kind of array, e.g., a=A(1); b=A(2); c=A(3); . . . etc. Inevitably we ask ourselves, is there a way to do this more simply? DISPERSE is syntactic sugar for performing these kinds of tasks with a single function call.

DISPERSE is not the same as DEAL. For example, if A is a vector then [a b c d] = disperse(A) performs a=A(1), b=A(2), c=A(3), and d=A(4), whereas [a b c d] = deal(A) performs a=A, b=A, c=A, and d=A.

DISPERSE generalizes to arbitrary dimensions, and is extended to follow analogous behavior on cell arrays and structure arrays. For example, if A is an RGB image, then [r g b] = disperse(A) grabs the R, G, and B color channels from A. See the documentation for more examples.

---------
Edit: I was recently notified that there is a similar submission called VECT2VAR. For vector inputs, these functions are equivalent; however, DISPERSE also works on higher-dimensional objects, which is handy when dealing with matrices, images, videos, etc.

Cita come

Sam Hallman (2024). disperse (https://www.mathworks.com/matlabcentral/fileexchange/33866-disperse), MATLAB Central File Exchange. Recuperato .

Compatibilità della release di MATLAB
Creato con R2009b
Compatibile con qualsiasi release
Compatibilità della piattaforma
Windows macOS Linux
Categorie
Scopri di più su Structures in Help Center e MATLAB Answers
Riconoscimenti

Ispirato: Surface area

Community Treasure Hunt

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

Start Hunting!
Versione Pubblicato Note della release
1.2.0.0

Edited the description to acknowledge a related submission. Edited the comments to mention the html documentation.

1.0.0.0