Advertisement
Guest User

Untitled

a guest
Aug 29th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %%%%%%%%% NEUROMECHANICS %%%%%%%%%%%%%
  3. % (c) Francisco Valero-Cuevas
  4. % October 2013, version 1.0
  5. % Filename: zonotope_muti_N.m
  6. clear all
  7. close all
  8. clc
  9. % This script shows how to map N-dimensional N-cubes into 2D and 3D via a
  10. % random H matrix of dimensions 2 x N and 3 x N, respectively.
  11.  
  12. % It then plots the convex hulls of the zonotopes when considering
  13. % the input to be between 3 and 8 dimensions. That is, a system having 3 to
  14. % 8 muscles
  15.  
  16. %%%%%%%%%%%%%%%%%%% User Input %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  17. % Enter the dimensions of the input space here. Note it must be >=3
  18. input_dim = 8 % this is the largest dimension
  19.  
  20.  
  21. H= rand(3,input_dim)*2-1 % this is the random full 3x8 H matrix. 'rand'
  22. % returns values between 0 and 1
  23. figure(2)
  24.  
  25. % Iterate to calculate the zonotopes for inout dimensions from 3 to 8
  26.  
  27. for n=3:8 % n us the number if muscles, from 3 to 8 in this example
  28. % use my function ncube to obtain the vertices. Use 'help ncube' for
  29. % details. X is the matrix of all vertices of the n-cube
  30. [X, count] = ncube(n);
  31. H2= H(1:2,1:n); %select the 2D output with n muscles
  32. % H3= H(1:3,1:n); %select the 3D output with n muscles
  33.  
  34. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  35. % 2D case
  36. % multiply each vertex by the matrix H
  37. Y=[];
  38. for i=1:count
  39.  
  40. Y= [Y;(H2*X(i,:)')'];
  41. end
  42.  
  43. % Find the convex hull
  44. K = convhull(Y);
  45.  
  46. % plot all points and the convex hull.
  47. figure(2)
  48. hold on
  49. plot(Y(K,1),Y(K,2),'r-')
  50.  
  51. indices = find(Y(:,2)== max(Y(:,2)));
  52. nlable = indices(1)
  53. text(Y(nlable,1),Y(nlable,2),['\leftarrow ' num2str(n) ' muscles' ] ,'FontSize',18)
  54.  
  55.  
  56. end
  57. hold off
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement