《MATLAB语言》上机实验报告 班级: 终极一班 学号:9527 姓名:小丢
实验12 高级图形用户界面设计(1)
1. 教材《MATLAB基础与实例进阶》P.169页,思考与练习2 操作题(1)-(2)
(1)建立一个图形窗口,使之背景颜色为红色,并在窗口上保留原有的菜单项,而且在按下鼠标器的左键之后显示Left Button Pressed字样。
h0=figure('Color',[1,0,0],'Name','图形窗口','Numbertitle','off','WindowButtonDownFcn','text(0.35,0.5,''Left Button Pressed'')','toolbar','none');
(2)利用图形对象绘制下列曲线,要求先用默认属性创建线条对象,再通过句柄操作改变曲线颜色、线型和线宽,并利用文本对象给曲线添加标注。
clc;clear all;close all; x1=0:.001:1;
y1=(1+x1.^2)/(1+x1.^4); subplot(311)
hline1=plot(x1,y1) x2=0:pi/100:2*pi;
y2=3*x2+sin(x2)-exp(x2); subplot(312)
hline2=plot(x2,y2) x3=-1000:1:1000;
y3=log(x3+sqrt(1+x3.^2))/2; subplot(313)
hline3=plot(x3,y3)
set(hline1,'color','r','linestyle','-','linewidth',0.5); set(hline2,'color','g','linestyle','+','linewidth',0.5); set(hline3,'color','b','linestyle','.','linewidth',0.5); gtext('y=(1+x^2)/(1+x^4);'); gtext('y=3*x+sin(x)-exp(x)'); gtext('y=log(x+sqrt(1+x^2))/2');
要求:只需给出程序,不要列出运行结果。
《MATLAB语言》上机实验报告 班级: 终极一班 学号:9527 姓名:小丢 实验13 高级图形用户界面设计(2)
1. 教材《MATLAB基础与实例进阶》P.169页,思考与练习2 操作题(3)-(4)
(3)在一个图形窗口中创建两坐标轴用以显示不同图形,并创建快捷菜单以改变曲线颜色
clc;clear all;close all;
h0=figure('toolbar','none','menubar','none','position',[380 200 500 350],... 'name','控件的综合应用'); %创建图形窗口
h_axes1=axes('Position',[0.07 0.08 0.4 0.45],'box','on'); %创建坐标轴 h_axes2=axes('Position',[0.55 0.43 0.42 0.45],'box','on'); %创建坐标轴 %在第一个坐标轴上画图
t=0:0.01:6*pi; yy=cos(t); b=1/2/pi;
h_line=plot(h_axes1,t,yy,'LineWidth',2); axis([-0.5 20 -1.2 1.2]); %在第二个坐标轴上画图
t=0:0.01:6*pi; yy=sin(t); b=1/2/pi;
h_line2=plot(h_axes2,t,yy,'LineWidth',2); axis([-0.5 20 -1.2 1.2]);
h_menu1=uimenu('label','颜色1'); %创建菜单 h_submenu11=uimenu(h_menu1,'label','红色','callback',... 'axes(h_axes2);set(h_line,''color'',''r'');');
h_submenu12=uimenu(h_menu1,'label','绿色','callback',... 'axes(h_axes2);set(h_line,''color'',''g'');');
h_submenu13=uimenu(h_menu1,'label','黑色','callback',... 'axes(h_axes2);set(h_line,''color'',''k'');');
h_submenu14=uimenu(h_menu1,'label','紫红色','callback',... 'axes(h_axes2);set(h_line,''color'',''m'');');
h_submenu15=uimenu(h_menu1,'label','黄色','callback',... 'axes(h_axes2);set(h_line,''color'',''y'');');
h_menu2=uimenu('label','颜色2'); %创建菜单 h_submenu21=uimenu(h_menu2,'label','红色','callback',... 'axes(h_axes2);set(h_line2,''color'',''r'');');
h_submenu22=uimenu(h_menu2,'label','绿色','callback',... 'axes(h_axes2);set(h_line2,''color'',''g'');');
h_submenu23=uimenu(h_menu2,'label','黑色','callback',... 'axes(h_axes2);set(h_line2,''color'',''k'');');
h_submenu24=uimenu(h_menu2,'label','紫红色','callback',... 'axes(h_axes2);set(h_line2,''color'',''m'');');
h_submenu25=uimenu(h_menu2,'label','黄色','callback',... 'axes(h_axes2);set(h_line2,''color'',''y'');');
h_menu3=uimenu('label','关闭图形窗口','callback','close(h0);'); %创建菜单
要求:只需给出程序,不要列出运行结果。
《MATLAB语言》上机实验报告 班级: 终极一班 学号:9527 姓名:小丢 (4) 设计一个计算器,实现简单的加、减、乘、除运算
function varargout = work(varargin) % WORK M-file for work.fig
% WORK, by itself, creates a new WORK or raises the existing % singleton*. %
% H = WORK returns the handle to a new WORK or the handle to % the existing singleton*. %
% WORK('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in WORK.M with the given input arguments. %
% WORK('Property','Value',...) creates a new WORK or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before work_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application % stop. All inputs are passed to work_OpeningFcn via varargin. %
% *See GUI Options on GUIDE's Tools menu. Choose \% instance to run (singleton)\%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help work
% Last Modified by GUIDE v2.5 17-Dec-2013 11:40:56
% Begin initialization code - DO NOT EDIT gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @work_OpeningFcn, ... 'gui_OutputFcn', @work_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1}); end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else
gui_mainfcn(gui_State, varargin{:}); end
% End initialization code - DO NOT EDIT
% --- Executes just before work is made visible.
function work_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
要求:只需给出程序,不要列出运行结果。
《MATLAB语言》上机实验报告 班级: 终极一班 学号:9527 姓名:小丢 % varargin command line arguments to work (see VARARGIN)
% Choose default command line output for work handles.output = hObject;
% Update handles structure guidata(hObject, handles);
% UIWAIT makes work wait for user response (see UIRESUME) % uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line. function varargout = work_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'0'); set(handles.text1,'String',textString);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'1'); set(handles.text1,'String',textString);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles) % hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'2'); set(handles.text1,'String',textString);
要求:只需给出程序,不要列出运行结果。
《MATLAB语言》上机实验报告 班级: 终极一班 学号:9527 姓名:小丢
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles) % hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'3'); set(handles.text1,'String',textString);
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'4'); set(handles.text1,'String',textString);
% --- Executes on button press in pushbutton6.
function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'5'); set(handles.text1,'String',textString);
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'6'); set(handles.text1,'String',textString);
% --- Executes on button press in pushbutton8.
function pushbutton8_Callback(hObject, eventdata, handles) % hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString=get(handles.text1,'String'); textString=strcat(textString,'7');
要求:只需给出程序,不要列出运行结果。