extracting value from a vector

John W. Eaton jwe at octave.org
Tue Apr 21 12:21:41 CDT 2009


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.

jwe


More information about the Help-octave mailing list