您的位置:首页 > 编程语言 > MATLAB

MATLAB编写回调函数(部分 更新)

2015-01-11 16:33 260 查看
t=0:0.001:4*pi;

figure('menubar','none');

x=plot(t,sin(t));

grid on;

set(gca,'xlim',[0 2*pi]);

h1=uimenu('label','颜色设置');

c1=set(x,'Color','red');

c2=set(x,'Color','green');

c2=set(x,'Color','blue');

uimenu(h1,'label','红色','accelerator','R','callback',c1);

uimenu(h1,'label','绿色','accelerator','G','callback',c2);

uimenu(h1,'label','蓝色','accelerator','B','callback',c3);

x=rand(10,4);

figure;

h=uitable('data',x);

set(h,'units','normalized','position',[0.1 0.5 0.8 0.8]);

% msgbox('warning','title','warn');

% warndlg('warning');

a=inputdlg({'user name:'...

,'passward:'},...

'log in');

c=questdlg('Are you sure to close the dialog ?');

switch c,

case 'Yes'

disp('you choose yes !');

case 'No'

disp('you choose no !');

case 'Cancel'

disp('you choose cancle !');

end

a=get(handles.edit1,'String');

if isempty(a)

set(handles.edit1,'String','0');

end

guidata(hObject,handles);

a=get(handles.edit2,'String');

if isempty(a)

set(handles.edit2,'String','0');

end

guidata(hObject,handles);

a=get(handles.edit1,'String');

b=get(handles.edit2,'String');

c=str2num(a)*str2num(b);

set(handles.text3,'String',num2str(c));

guidata(hObject,handles);

a=get(handles.edit2,'String');

if isempty(a)

set(handles.edit2,'String','0');

end

guidata(hObject,handles);

h=gca;

cla(h);

set(handles.edit1,'String','10');

set(handles.edit2,'String','0');

set(handles.edit3,'String','1');

x=linspace(-5,5,50);

y=x;

for w=2:0.5:6

[X Y]=meshgrid(x,y);

Z=1/sqrt(2*pi)*w.*exp(-(X.^2+Y.^2))./2*w*w;

mesh(X,Y,Z);

axis equal;

pause(0.5);

end

a=str2num(get(handles.edit1,'String'));

b=str2num(get(handles.edit2,'String'));

c=str2num(get(handles.edit3,'String'));

x=linspace(-a,a,50);

y=linspace(-b,b,50);

w=c;

[X Y]=meshgrid(x,y);

Z=1/sqrt(2*pi)*w.*exp(-(X.^2+Y.^2))./2*w*w;

mesh(X,Y,Z);

axis equal;

h=gca;

cla(h);

set(handles.edit1,'String','0');

set(handles.edit2,'String','0');

set(handles.edit3,'String','1');

val=get(hObject,'Value');

str=get(hObject,'String');

switch str{val}

case 'peaks'

handles.current_data=handles.peaks;

case 'sphere'

handles.current_data=handles.sphere;

case 'sinc'

handles.current_data=handles.sinc;

end

guidata(hObject,handles);

+++++++++++++++++++++++++++++++++++++

h=figure;%创建一个窗口

% get(h) %获得h的所有属性

set(h,'units','normalized','menu','none',...

'Position',[0.1 0.1 0.5 0.5]); %设置h的有关属性

ha=axes;

set(ha,'parent',h,'units','normalized',...

'position',[0.1 0.1 0.8 0.8]);%注意此处为设置ha的属性

%指定其父对象为h,h不加引号

x=linspace(-8,8,1000);

y=sinc(x);

h1=line('parent',ha,'xdata',x,'ydata',y,...

'color','r');

str='bgrcmykw';

for i=1:length(str)

set(h1,'color',str(i));

pause(2);

end

h=figure('units','normalized','menu',...

'none','position',[0.1 0.1 0.5 0.5]);

ha=axes('parent',h,'units','normalized'...

,'position',[0.1 0.1 0.8 0.8]);

x=linspace(-5,5,100);

y=sinc(x);

h1=line('parent',ha,'xdata',x,...

'ydata',y,'color','r','linewidth',2);

str='dhopsx';

for i=1:length(str)

set(h1,'marker',str(i));

pause(2);

end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: