octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Proposed enhancement for vec()


From: Judd Storrs
Subject: Proposed enhancement for vec()
Date: Fri, 17 Dec 2010 10:57:23 -0500

I've proposed a patch to enhance octave's builtin vec() function.
https://savannah.gnu.org/patch/?7417

vec(x) is equivalent to x(:), but is useful if you need a function
handle. The result of vec(x) is a Nx1 matrix of elements in memory
order.

size(vec(x)) == [numel(x) 1]

In working with bsxfun, I've found that getting a vector with a
desired dimensionality can be tedious (or at least I couldn't find a
straightforward way to do it). The patch adds an optional second
parameter to shift the result so that the elements are along a
requested dimension. For example, with the patch applied:

size(vec(x,5)) == [1 1 1 1 numel(x)] == shiftdim(x(:),-4) ==
reshape(x,[1 1 1 1 numel(x)])

I'm not aware of a simple way to do this otherwise or generically
(e.g. in a wrapper function for ifft(x,n,dim) where a shift vector
should be applied along the desired dimension). vec() is an octave
extension that does not exist in Matlab, so compatibility is not an
issue. The primary benefit is improved semantics -- vec(x,10) is more
semantically direct than the reshape(...), shiftdim(...) constructs.


--judd


reply via email to

[Prev in Thread] Current Thread [Next in Thread]