|
From: | Rob Mahurin |
Subject: | Re: extracting value from a vector |
Date: | Tue, 21 Apr 2009 15:22:38 -0400 |
On Apr 21, 2009, at 1:21 PM, John W. Eaton wrote:
On 21-Apr-2009, Rob Mahurin wrote: | I want this often enough that I've written | | function varargout = columns_of (in) | [d1,d2] = size(in); | varargout = mat2cell(in, d1, ones(1,d2) ); | endfunction | | so I can do e.g. | | octave> v = rand(2,3), [a,b] = columns_of(v) | v = | 0.054753 0.509675 0.866045 | 0.702775 0.483820 0.816340 | a = | 0.054753 | 0.702775 | b = | 0.50968 | 0.48382 See also num2cell, {:}, and deal: v = rand (2, 3), [a, b, c] = deal (num2cell (v, 1){:}) However, unlike your function, deal requires nargout == nargin.
Would it make sense to modify deal.m to allow this use in a less cryptic way? Here's a (partial) patch that allows the above with
[a,b] = deal(v,"columns") Rob -- Rob Mahurin Department of Physics and Astronomy University of Tennessee 865 207 2594 Knoxville, TN 37996 address@hidden--- /usr/local/share/octave/3.0.3/m/general/deal.m 2009-02-01 17:23:24.000000000 -0500
+++ deal.m 2009-04-21 15:06:27.000000000 -0400 @@ -63,6 +63,11 @@ function [varargout] = deal (varargin) + if (nargin == 2 && strcmp (varargin(2),"columns")) + varargout = num2cell (varargin{1}, 1); + return; + endif + if (nargin == 0) print_usage (); elseif (nargin == 1 || nargin == nargout)
[Prev in Thread] | Current Thread | [Next in Thread] |