disperse

バージョン 1.2.0.0 (4.22 KB) 作成者: Sam Hallman
Assign elements of an input array to individual output variables with a single function call.
ダウンロード: 1.2K
更新 2011/11/30

ライセンスの表示

編集メモ: 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.

引用

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

MATLAB リリースの互換性
作成: R2009b
すべてのリリースと互換性あり
プラットフォームの互換性
Windows macOS Linux
カテゴリ
Help Center および MATLAB AnswersStructures についてさらに検索
謝辞

ヒントを与えたファイル: Surface area

Community Treasure Hunt

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

Start Hunting!
バージョン 公開済み リリース ノート
1.2.0.0

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

1.0.0.0