[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
A better way to act on a dim of an N-d array?
From: |
John W. Eaton |
Subject: |
A better way to act on a dim of an N-d array? |
Date: |
Fri, 01 Feb 2008 02:27:35 -0500 |
On 31-Jan-2008, Ben Abbott wrote:
|
| On Jan 29, 2008, at 10:35 PM, Ben Abbott wrote:
|
| >
| > On Jan 29, 2008, at 8:30 PM, Ben Abbott wrote:
| >
| >> While working on quantile and prctile functions for Octave, I am in
| >> need to functionally operate on the dim-th dimension of a N-d array.
|
| What I'm looking to do is allow a specific dimension of an N-d array
| to be acted upon by a function that returns a vector of a consistent
| length.
|
| The algirithms for calculating the quanitles of a sample are
| sufficiently varied that the methods used by mean(), median(), etc, to
| support N-d arrays, are insufficient for my application.
|
| As I am not a competent c/c++ programmer, I chose to do the job in an
| m-file ... but is there a better way to do this?
I'm not sure, but it does seem fairly complex. But if it is necessary
to use your dimfunc, then you should probably use
function y = dimfunc (func, x, dim, varargin)
instead of
function y = dimfunc (func, x, dim, arg1, arg2, arg3, arg4, arg5)
so that dimfunc can handle any number of additional arguments, not
just 5, and so you can replace
if (nargin == 3)
temp = func (xdim(:));
elseif (nargin == 4)
temp = func (xdim(:), arg1);
elseif (nargin == 5)
temp = func (xdim(:), arg1, arg2);
elseif (nargin == 6)
temp = func (xdim(:), arg1, arg2, arg3);
elseif (nargin == 7)
temp = func (xdim(:), arg1, arg2, arg3, arg4);
elseif (nargin == 8)
temp = func (xdim(:), arg1, arg2, arg3, arg4, arg5);
endif
with
temp = func (xdim(:), varargin{:});
jwe
- A better way to act on a dim of an N-d array?,
John W. Eaton <=