Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. function [vertices,count] = ncube(dim)
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. %%%%%%%%% NEUROMECHANICS %%%%%%%%%%%%%
  4. % (c) Francisco Valero-Cuevas
  5. % October 2013, version 1.0
  6. % Filename: ncube.m
  7.  
  8. % ncube returns the vertices of an n-cube for dimensions 3 or higher.
  9. % (c) Francisco Valero-Cuevas 2013
  10. % [vertices,count] = ncube(dim) returns:
  11. % the matrix 'vertices' with the vertices of the n-cube
  12. % the number 'count' of vetices
  13. if dim <3
  14. error('low dim', 'enter a dimension 3 or greater' )
  15. else
  16.  
  17. vertices = [0 0;1 0; 0 1 ; 1 1];
  18. new = [0 1];
  19. dim = dim-1;
  20. for n=2:dim
  21. temp2 = [];
  22. for i=1:length(vertices')
  23. row = vertices(i,:);
  24. temp1 = [0 row;
  25. 1 row];
  26. temp2 = [temp2;temp1];
  27. end
  28. vertices = temp2;
  29.  
  30. end
  31. vertices = sortrows(vertices);
  32. count = length(vertices');
  33.  
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement