matlab 小球,Matlab 小球绕跑道运动

发布时间:

Oct 21, 2012

更新时间:

Oct 21, 2012

总字数:210

阅读时间:1m

作者: 谢先斌

Matlab 小球绕跑道运动

代码

figure('numbertitle','off','name','Matlab Animation

Demo--matlabfan','MenuBar','none')

prompt={'请输入速度v','请输入长度L','请输入半径r'};

default={'5','10','2'};

v=5;L=10;r=2;

p=inputdlg(prompt,'输入参数',1,default);

v=str2double(p(1));

L=str2double(p(2));

r=str2double(p(3));

if v=0L=0r=0

warndlg('MATLABFAN提醒您:输入参数必须为整数','警告')

else

axis([0,2r+L,0,2r])

ox1=r;oy1=r;ox2=r+L;oy2=r;

x1=r0.015vr+L;

y1=2rones(size(x1));

thita=00.015vrpi;

x2=sin(thita)r+ox2;

y2=cos(thita)r+oy2;

x3=r+L-0.015vr;

y3=zeros(size(x3));

x4=-sin(thita)r+ox1;

y4=-cos(thita)r+oy1;

x=[x1 x2 x3 x4];

y=[y1 y2 y3 y4];

plot(x,y);

text(0,-2,['长度L=' num2str(L) ' , ' '半径r=' num2str(r) ' , ' '速度v=' num2str(v)]);

axis equal

set(gca,'Visible','off')

hm=line(r,2r,'color','red','marker','.','markersize',37,'erasemode','xor');

while 1

for i=1length(x)

try

set(hm,'xdata',x(i),'ydata',y(i));

pause(0.0003)

drawnow

catch

'www.xiexianbin.cn

return

end

end

end

end

效果

dcc4a5a839481bbbbc2f591e70131916.png

MATLAB_GUI控制小球加减速运动 btn.start.m function btn_start() global hball ipos delt isforward npos ispaused x y ispaused = false; while (1) set(hball, 'xdata', x(ipos), 'ydata', y(ipos)); drawnow; pause(delt); ipos = ipos-(-1)^isforward; if ipos==npos+1 ipos = 1; elseif ipos == 0 ipos = npos; end if ispaused break end end ball.m hfigure = figure('name', '控制小球运动 ver 1.0', 'menubar', 'none', 'numbertitle', 'off', 'position', [600 200 350 400], 'visible', 'off'); global hball ipos delt isforward npos ispaused x y haxes = axes('position', [0.25 0.45 0.5 0.5], 'visible', 'off'); axis equal t = 0:0.1:2*pi+0.1; x = sin(t); y = cos(t); line(x, y, 'linewidth', 2); set(0, 'defaultuicontrolbackgroundcolor', get(hfigure, 'color')); set(0, 'defaultuicontrolfontsize', 12); set(0, 'defaultuicontrolunits', 'points'); hball = line('xdata', 0, 'ydata', 1, 'marker', 'o', 'markerfacecolor', 'r', 'markersize', 15); npos = length(t); ipos = 1; delt = 0.01; ispaused = false; isforward = true; uicontrol('string', '开始', 'position', [30 50 50 20], 'callback', 'btn_start;'); uicontrol('string', '停止', 'position', [100 50 50 20], 'callback', 'ispaused = true;'); uicontrol('string', '换向', 'position', [170 50 50 20], 'callback', 'isforward = ~isforward;'); uicontrol('string', '退出', 'position', [100 20 50 20], 'callback', ['ispaused = true;', 'closereq;', ... 'clear delt hball ipos ispaused t y haxes hfigure isforward npos x;']); uicontrol('style', 'slider', 'value', 0.5, 'position', [40 90 190 15], 'callback', 'delt = get(gcbo, ''value'')/100+0.01;'); uicontrol('style', 'text', 'position', [40 110 190 20], 'fontsize', 12, 'string', 'speed'); % newicon = javax.swing.imageicon('1.png'); % figframe = get(hfigure, 'javaframe'); % figframe.setfigureicon(newicon); set(hfigure, 'visible', 'on');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值