No BSD License  

Highlights from
submat_noeval

Be the first to rate this file! 0 Downloads (last 30 days) File Size: 1 KB File ID: #19350

submat_noeval

by Garrett Euler

 

27 Mar 2008 (Updated 03 Apr 2008)

Returns the input matrix reduced along indicated dimensions (without eval)

| Watch this File

File Information
Description

This is similar to the submat function I submitted earlier (file id 19324) except that it does not use EVAL. Accordingly it loses the flexibility offered by EVAL.

This is a function to aid/simplify access to subsections of a n-d matrix.

Y=SUBMAT_NOEVAL(X,DIM,LIST) creates a matrix Y that is the matrix X reduced along dimension DIM to the indices in LIST. If DIM is a list of dimensions, LIST is used to reduce each dimension.

Y=SUBMAT_NOEVAL(X,DIM1,LIST1,DIM2,LIST2,...) allows for access to multiple dimensions independently.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
submat
This submission has inspired the following:
subarray

MATLAB release MATLAB 7.5 (R2007b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (3)
31 Mar 2008 Duane Hanselman

Since you did not simply update your previous submission of the same name, please delete it today. It is inappropriate to have two identically named functions from the same author.

03 Apr 2008 Jos x@y.z

I have some problems understanding this code:
Apparently, -- Y = submat_noeval(X,D,F) -- is the same as -- ind(1:ndims(X)) = {':'} ; ind{D} = F ; Y = X(ind{:}) --

which would allow for a much simpler code:
Y = fun(X,varargin)
ind(1:ndims(X)) = {':'} ;
i = 1:2:nargin-1 ;
ind{[varargin{i}]} = deal(varargin{i+1}) ;
Y = X(ind{:}) ;

Please correct me if I am wrong ...

03 Apr 2008 Garrett Euler

Yea I did not know that one. Matlab takes the string ':' as a special case when indexing matrices...anything else like '1:2' etc though doesn't work without an eval. Thanks, I'll update!

Please login to add a comment or rating.
Updates
31 Mar 2008

Name change and updated description.

03 Apr 2008

Updated using suggestions from Jos.

Tag Activity for this File
Tag Applied By Date/Time
matrices Garrett Euler 22 Oct 2008 09:55:34
submatrix subset subarray Garrett Euler 22 Oct 2008 09:55:34

Contact us at files@mathworks.com