Code covered by the BSD License  

Highlights from
INDIM

5.0

5.0 | 1 rating Rate this file 4 Downloads (last 30 days) File Size: 1.93 KB File ID: #8580
image thumbnail

INDIM

by Peter (PB) Bodin

 

28 Sep 2005 (Updated 25 Oct 2006)

Picks, or assigns elements to, a hyperplane defined by indices and a dimension.

| Watch this File

File Information
Description

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.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (1)
05 Oct 2005 Jos x

either needs to be incorporated in R15
or given as an example in the docs ;-)

Please login to add a comment or rating.
Updates
30 Sep 2005

Added some error checking

30 May 2006

Added assignment functionality. Improved error checking. Added a silly screenshot.

06 Sep 2006

Corrected an error in the help section.

25 Oct 2006

Corrected a typo in the description

Tag Activity for this File
Tag Applied By Date/Time
matrices Peter (PB) Bodin 22 Oct 2008 08:01:00
index Peter (PB) Bodin 22 Oct 2008 08:01:00
dimension Peter (PB) Bodin 22 Oct 2008 08:01:00
nd Peter (PB) Bodin 22 Oct 2008 08:01:00
assign Peter (PB) Bodin 22 Oct 2008 08:01:00
hyperplane Peter (PB) Bodin 22 Oct 2008 08:01:00

Contact us at files@mathworks.com