untitled10.m

来自「推箱子游戏,这是用matlab语言编写的源程序」· M 代码 · 共 40 行

M
40
字号
close all;clc;clear;
st=1; % deafault step length
figure;
set(gcf,'DoubleBuffer','on');
aa=axes('position',[0.1,0.1,0.8,0.6]);hold on;
set(aa,'ButtonDownFcn',['po=get(gca,''CurrentPoint'');',...
        'set(pr,''XData'',po(1)*[1,1]);',...
    'ck=get(gcf,''CurrentKey'')']);
set(gcf,'KeyPressFcn',['ck=get(gcf,''CurrentKey'');',...
        'switch ck; case ''leftarrow''; s=-1;case ''rightarrow'';s=1;end;',...
        'set(pr,''XData'',get(pr,''XData'')+s*st);']); 
% \copyright: zjliu
% Author's email: zjliu2001@163.com
uicontrol(gcf,'style','push','unit','normalized',...
    'position',[0.12,0.9,0.6,0.07],...
    'string','Please select data file for x-axis:',...
    'fontsize',16,'fontname','times new roman',...
    'BackgroundColor',[0.8,0.8,0.8],'callback',[...
        '[filenamex, pathnamex] = uigetfile;',...
        'dx=plot([pathnamex,filenamex]);dx=dx(:);']);
uicontrol(gcf,'style','push','unit','normalized',...
    'position',[0.12,0.82,0.6,0.07],...
    'string','Please select data file for y-axis:',...
    'fontsize',16,'fontname','times new roman',...
    'BackgroundColor',[0.8,0.8,0.8],'callback',[...
        '[filenamey, pathnamey] = uigetfile;',...
        'dy=plot([pathnamey,filenamey]);dy=dy(:);',...
        'if isempty(dx);dx=[1:length(dy)]'';end;plot(dx,dy);']);
uicontrol(gcf,'style','push','unit','normalized',...
    'position',[0.12,0.74,0.6,0.07],...
    'string','using random number for y-axis:',...
    'fontsize',16,'fontname','times new roman','ForegroundColor','r',...
    'BackgroundColor',[0.8,0.8,0.8],'callback',[
    'plot(1:100,rand(100,1));']);
uicontrol(gcf,'style','push','unit','normalized',...
    'position',[0.74,0.74,0.24,0.07],...
    'string','show red line',...
    'fontsize',16,'fontname','times new roman','ForegroundColor','r',...
    'BackgroundColor',[0.8,0.8,0.8],'callback',[
    'hold on;pr=plot(mean(xlim)*[1,1],ylim,''r'',''linewidth'',1);']);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?