0
|
1 ## Copyright (C) 2001 Laurent Mazet |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify |
|
4 ## it under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2 of the License, or |
|
6 ## (at your option) any later version. |
|
7 ## |
|
8 ## This program is distributed in the hope that it will be useful, |
|
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 ## GNU General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with this program; if not, write to the Free Software |
|
15 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
16 |
|
17 ## usage: M = vec2mat (V, c [, d]) |
|
18 ## |
|
19 ## Converts the vector V into a c column matrix with row priority |
|
20 ## arrangement and with the final column padded with the value d |
|
21 ## to the correct length. |
|
22 ## |
|
23 ## V: vector |
|
24 ## c: number of colunms |
|
25 ## d: value of padded elements (default 0) |
|
26 ## |
|
27 ## M: matrix. |
|
28 |
|
29 ## 2001-02-02 |
|
30 ## initial release |
|
31 |
|
32 function M = vec2mat (V, c, val) |
|
33 |
|
34 switch (nargin) |
|
35 case 1, |
|
36 M = V; |
|
37 return; |
|
38 case 2, |
|
39 val = 0; |
|
40 case 3, |
|
41 val = val; |
|
42 otherwise |
|
43 error ("usage: M = vec2mat (V, c [, d])"); |
|
44 endswitch |
|
45 |
|
46 V = V.'; |
|
47 V = V(:); |
|
48 |
|
49 r = ceil (length (V) / c); |
|
50 |
|
51 d = r * c - length (V); |
|
52 if (d != 0) |
|
53 V = [ V ; val*ones(d, 1) ]; |
|
54 endif |
|
55 |
|
56 M = reshape (V, c, r).'; |
|
57 |
|
58 endfunction |