sub2allind

版本 1.5.0.0 (2.7 KB) 作者: Michael Völker
convert subscripts to ALL corresponding indices
653.0 次下载
更新时间 2012/2/7

查看许可证

idx = sub2allind(sz, sub1, sub2, sub3, ... )

Like Matlab's sub2ind, sub2allind computes the equivalent linear indices for
given subscripts of an array with size SZ.
Unlike sub2ind, it computes a field of all combinations of
subscripts. So, instead of calling A( 2:3, 1, 4:11) you might
use
linIdx = sub2allind( size(A), 2:3, 1, 4:11 );

and then call A(linIdx) or A(linIdx(:)) or you reshape linIdx the way you need.

This is usefull whenever you want to access a subset of an array and compare it with a differently shaped thing, like

A(linIdx(:)) = A(linIdx(:)) + <1D-Vector>

Using the naked colon operator is allowed to reference an entire dimension:

linIdx = sub2allind( sz, :, sub2 );

引用格式

Michael Völker (2024). sub2allind (https://www.mathworks.com/matlabcentral/fileexchange/30096-sub2allind), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R2011a
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Matrix Indexing 的更多信息
致谢

启发作品: CATPAD, N-dimensional sparse arrays

Community Treasure Hunt

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

Start Hunting!
版本 已发布 发行说明
1.5.0.0

Added H1 line; fixed bug when asking for a column of indices only

1.4.0.0

* shape of output fits the adressed field now
* little more docu and error checking

1.1.0.0

* Implemented colon operator (Thanks to Matt J)
* possible errors catched; more comments

1.0.0.0