-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrand_path.m
42 lines (35 loc) · 1.04 KB
/
rand_path.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
function [path, n_u]=rand_path(SG)
%RAND_PATH_MIXIM Summary of this function goes here
%
% Completely random path through the uninformed nodes in simulation grid
% Supports 2D and 3D simulation grids.
%
% outputs:
% path: random path
% n_u: number of uninformed nodes
%Uninformed nodes
uninformed = isnan(SG);
% Number of uninformed nodes
n_u = sum(sum(sum(uninformed)));
switch length(size(SG))
case 2 %2D
% Size of simulation grid
[nx, ny] = size(SG);
X=1:nx;
Y=1:ny;
[XX,YY]=meshgrid(X,Y);
%create raster path
path = [XX(uninformed(1:end))',YY(uninformed(1:end))'];
case 3 %3D
% Size of simulation grid
[nx, ny, nz] = size(SG);
X=1:nx;
Y=1:ny;
Z=1:nz;
[XX,YY,ZZ]=meshgrid(X,Y,Z);
%create raster path
path = [XX(uninformed(1:end))',YY(uninformed(1:end))',...
ZZ(uninformed(1:end))'];
end
%randomize path
path = path(randperm(n_u),:);