Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- % Major Functions File for Array the 2-D Irregular Sample Space for 8-Direction Random Walk
- % Author: Edward J. Xu, edxu96@outlook.com
- % Date: 190616
- % Version: 1.0
- % ######################################################################################################################
- function [cellSampleSpace] = getCellSampleSpace2dim(vecData1, vecData2, n1, n2, funcLogic)
- cellSampleSpace = {};
- for i = 1:n1
- for j = 1:n2
- if funcLogic(vecData1(i), vecData2(j))
- cellSampleSpace{end + 1} = [vecData1(i), vecData2(j)];
- end
- end
- end
- cellSampleSpace = cellSampleSpace(randperm(length(cellSampleSpace)));
- end
- function [cellArraySSpace] = arrangeSampleSpace2dim(cellSampleSpace, nRow)
- nCol = length(cellSampleSpace) / nRow;
- if mod(nCol, 1) ~= 0
- error("nRow is impossible!!!")
- end
- cellArraySSpace = {};
- k = 1;
- for i = 1:nRow
- for j = 1:nCol
- cellArraySSpace(i, j) = cellSampleSpace(k);
- k = k + 1;
- end
- end
- end
- function [vecCandidate] = loopRandWalk2Dim(cellArraySSpace, vecPre)
- [m, n] = size(cellArraySSpace);
- % Find where vecPre is
- where = 1;
- while ~isequal(cellArraySSpace{where}, vecPre)
- where = where + 1;
- end
- [x, y] = returnPosition(where, m, n);
- % disp(x)
- % disp(y)
- if cellArraySSpace{x, y} ~= cellArraySSpace{where}
- error("Error when trying to find where the x is.")
- end
- % Random Walk
- x = loopRandWalk(x, m, 1);
- y = loopRandWalk(y, n, 1);
- % disp(x)
- % disp(y)
- vecCandidate = [cellArraySSpace{x, y}];
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement