数学建模社区-数学中国

标题: 【MATLAB动画教程六】 [打印本页]

作者: 士心之约    时间: 2015-9-17 20:49
标题: 【MATLAB动画教程六】
  1. %小球绕跑道运动
  2. %rewrite by dynamic
  3. %more information please go to http://www.matlabsky.cn
  4. %
  5. figure('numbertitle','off','name',...
  6. 'Matlab Animation Demo--by matlabsky','MenuBar','none')
  7. prompt={'请输入速度v:','请输入长度L:','请输入半径r:'};
  8. default={'5','10','2'};
  9. v=5;L=10;r=2;
  10. p=inputdlg(prompt,'输入参数',1,default);
  11. v=str2double(p(1));
  12. L=str2double(p(2));
  13. r=str2double(p(3));
  14. if v<=0|L<=0|r<=0
  15. warndlg('Matlabsky提醒您:输入参数必须为整数','警告')
  16. else
  17. axis([0,2*r+L,0,2*r])
  18. ox1=r;oy1=r;ox2=r+L;oy2=r;
  19. x1=r:0.015*v:r+L;
  20. y1=2*r*ones(size(x1));
  21. thita=0:0.015*v/r:pi;
  22. x2=sin(thita)*r+ox2;
  23. y2=cos(thita)*r+oy2;
  24. x3=r+L:-0.015*v:r;
  25. y3=zeros(size(x3));
  26. x4=-sin(thita)*r+ox1;
  27. y4=-cos(thita)*r+oy1;
  28. x=[x1 x2 x3 x4];
  29. y=[y1 y2 y3 y4];
  30. plot(x,y);
  31. text(0,-2,['长度L=' num2str(L) ',' ...
  32. '半径r=' num2str(r) ',' '速度v=' num2str(v)]);
  33. axis equal
  34. set(gca,'Visible','off')
  35. hm=line(r,2*r,'color','red','marker','.','markersize',37,'erasemode','xor');
  36. while 1
  37. for i=1:length(x)
  38. try
  39. set(hm,'xdata',x(i),'ydata',y(i));
  40. pause(0.0003)
  41. drawnow
  42. catch
  43. ['MatlabSky--打造最优、专业和权威的Matlab技术交流平台!'...
  44. '更多信息参见:<a href="matlab:web'...
  45. 'http://www.matlabsky.cn"> http://www.matlabsky.cn</a>']
  46. return
  47. end
  48. end
  49. end
  50. end
复制代码






欢迎光临 数学建模社区-数学中国 (http://www.madio.net/) Powered by Discuz! X2.5