INDIM

版本 1.0.0.0 (1.9 KB) 作者: Peter (PB) Bodin
Picks, or assigns elements to, a hyperplane defined by indices and a dimension.
1.6K 次下载
更新时间 2006/10/25

查看许可证

function C = indim(A,dim,inds,B)
INDIM Picks, or assigns elements to, a hyperplane defined by indices and a dimension.
INDIM(A,dim,inds) picks the elements in the hyperplane defined by inds and dim.

Let A = RAND(4,4,4,4,4,4), then

C = INDIM(A,3,2:3)
returns the same as A(:,:,2:3,:,:,:)

C = INDIM(A,3,2:3,B)
assigns the values of B to the hyperplane of A such that A(:,:,2:3,:,:,:) = B
If B is not a scalar or is not the same size and shape as the hyperplane defined by dim and inds, indim tries to reshape it into the right shape. If the number of elements are inconsistent, an error is thrown.

Examples:
A=reshape(1:16,[2 2 2 2]);
C=indim(A,3,1)

A=reshape(1:16,[2 2 2 2]);
C=indim(A,2,1,NaN)

A=reshape(1:16,[2 2 2 2]);
C=indim(A,1,1,[-16:-8])

Thanks to:

Richard Hindmarsh for suggesting the assignment functionality.
Doug Schwarz for proposing a solution to the same functionality.

引用格式

Peter (PB) Bodin (2024). INDIM (https://www.mathworks.com/matlabcentral/fileexchange/8580-indim), MATLAB Central File Exchange. 检索来源 .

MATLAB 版本兼容性
创建方式 R14SP3
兼容任何版本
平台兼容性
Windows macOS Linux
类别
Help CenterMATLAB Answers 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

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

Corrected a typo in the description