Rev | Line | |
---|
[37] | 1 | function x = ndgridmat(varargin) |
---|
| 2 | %NDGRIDMAT Matrix of grid points. |
---|
| 3 | % y = NDGRIDMAT(x1,x2,...) returns one matrix containing all grid points |
---|
| 4 | % as rows. It is the same as concatenating the results of NDGRID. |
---|
| 5 | % First dimension varies fastest: |
---|
| 6 | % y(1,:) = [x1(1) x2(1) ...] |
---|
| 7 | % y(2,:) = [x1(2) x2(1) ...] |
---|
| 8 | |
---|
| 9 | % Written by Tom Minka |
---|
| 10 | % (c) Microsoft Corporation. All rights reserved. |
---|
| 11 | |
---|
| 12 | d = length(varargin); |
---|
| 13 | if d == 1 |
---|
| 14 | x = varargin{1}(:); |
---|
| 15 | return; |
---|
| 16 | end |
---|
| 17 | |
---|
| 18 | len = zeros(1,d); |
---|
| 19 | for i = 1:d |
---|
| 20 | len(i) = length(varargin{i}); |
---|
| 21 | end |
---|
| 22 | n = prod(len); |
---|
| 23 | x = zeros(n,d); |
---|
| 24 | k = 1; |
---|
| 25 | for i = 1:d |
---|
| 26 | xi = varargin{i}(:); |
---|
| 27 | % might use reparray here |
---|
| 28 | x(:,i) = repmat(kron(xi, ones(k,1)), n/k/len(i), 1); |
---|
| 29 | k = k * len(i); |
---|
| 30 | end |
---|
Note: See
TracBrowser
for help on using the repository browser.