disperse

Assign elements of an input array to individual output variables with a single function call.
1,2K téléchargements
Mise à jour 30 nov. 2011

Afficher la licence

Note de l’éditeur : 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.

Citation pour cette source

Sam Hallman (2024). disperse (https://www.mathworks.com/matlabcentral/fileexchange/33866-disperse), MATLAB Central File Exchange. Récupéré le .

Compatibilité avec les versions de MATLAB
Créé avec R2009b
Compatible avec toutes les versions
Plateformes compatibles
Windows macOS Linux
Catégories
En savoir plus sur Structures dans Help Center et MATLAB Answers
Remerciements

A inspiré : Surface area

Community Treasure Hunt

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

Start Hunting!
Version Publié le Notes de version
1.2.0.0

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

1.0.0.0