Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. % Major Functions File for Array the 2-D Irregular Sample Space for 8-Direction Random Walk
  2. % Author: Edward J. Xu, edxu96@outlook.com
  3. % Date: 190616
  4. % Version: 1.0
  5. % ######################################################################################################################
  6.  
  7.  
  8. function [cellSampleSpace] = getCellSampleSpace2dim(vecData1, vecData2, n1, n2, funcLogic)
  9. cellSampleSpace = {};
  10. for i = 1:n1
  11. for j = 1:n2
  12. if funcLogic(vecData1(i), vecData2(j))
  13. cellSampleSpace{end + 1} = [vecData1(i), vecData2(j)];
  14. end
  15. end
  16. end
  17. cellSampleSpace = cellSampleSpace(randperm(length(cellSampleSpace)));
  18. end
  19.  
  20.  
  21. function [cellArraySSpace] = arrangeSampleSpace2dim(cellSampleSpace, nRow)
  22. nCol = length(cellSampleSpace) / nRow;
  23. if mod(nCol, 1) ~= 0
  24. error("nRow is impossible!!!")
  25. end
  26. cellArraySSpace = {};
  27. k = 1;
  28. for i = 1:nRow
  29. for j = 1:nCol
  30. cellArraySSpace(i, j) = cellSampleSpace(k);
  31. k = k + 1;
  32. end
  33. end
  34. end
  35.  
  36.  
  37. function [vecCandidate] = loopRandWalk2Dim(cellArraySSpace, vecPre)
  38. [m, n] = size(cellArraySSpace);
  39. % Find where vecPre is
  40. where = 1;
  41. while ~isequal(cellArraySSpace{where}, vecPre)
  42. where = where + 1;
  43. end
  44. [x, y] = returnPosition(where, m, n);
  45. % disp(x)
  46. % disp(y)
  47. if cellArraySSpace{x, y} ~= cellArraySSpace{where}
  48. error("Error when trying to find where the x is.")
  49. end
  50. % Random Walk
  51. x = loopRandWalk(x, m, 1);
  52. y = loopRandWalk(y, n, 1);
  53. % disp(x)
  54. % disp(y)
  55. vecCandidate = [cellArraySSpace{x, y}];
  56. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement