文件名称:MATLAB_GUI控制小球加减速运动
文件大小:1000B
文件格式:RAR
更新时间:2021-08-13 16:29:44
MATLAB
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');
【文件预览】:
btn_start.m
ball.m