《MATLAB课程设计》报告

时间:2024.3.10

MATLAB课程设计报告

MATLAB课程设计报告

《MATLAB课程设计》报告

设计题目: MATLAB课程设计(简单计算器) 学生姓名:

学生学号: 201004444300 专业班级: 光信息

答辩时间: 2013-12

指导教师: 冯明库

广东技术师范学院

电子与信息学院

一、设计目的及意义

1、运用MATLAB实现MATLAB的GUI程序设计。

2、熟悉和掌握MATLAB 程序设计方法。

3、掌握MATLAB GUI 程序设计。

二、设计任务及指标

要求利用MATLAB GUI设计实现一个图形用户界面的计算器程序,要求实现:

A. 具有友好的用户图形界面。实现十进制数的加、减、乘、除、乘方、取模等简单计算。

B. 科学计算函数,包括(反)正弦、(反)余弦、(反)正切、(反)余切、开方、指数等运行。

C. 能够保存上次历史计算的答案,先是答案存储器中得内容。

D. 有清除键,能清除操作,并对不正确的表达式能指出其错误原因。

E. 独立存储器功能,使之可以直接输入存储器,可与存储器中的数值相加减。能够清除独立存储器中的内容。

三、设计过程

1.启动MATLAB

2.观察MATLAB窗口的各个组成部分

1)了解菜单栏各菜单功能,用鼠标打开MATLAB各个菜单,在状态栏里显示当前鼠标所指的菜单项的含义。

2)用鼠标指向常用工具栏的每个工具按钮,了解其含义。

3、题目分析,了解各显示框的分布和功能,然后在通过各个按钮的回调函数,实现简单的计算功能。

4、总体设计,首先用MATLAB GUI功能,在绘制一个静态文本框和一个文本编辑框,以及每个命令按钮,调整好各控件大小、颜色,整体布局。

5、具体设计,实现各功能界面设计。

四、结论及分析[2]

4.1 各功能界面设计

MATLAB课程设计报告

4.2 各功能模块实现

算法设计:

A. 数字键设计:0—9以及小数点函数都一样,只是参数不同: global jj

textString=get(handles.text1,'String');

if(strcmp(textString,'0.')==1)&(jj==0) set(handles.text1,'String','1')

else

textString=strcat(textString,'1');

set(handles.text1,'String',textString)

end jj=0;

B. 四则运算函数:

textString=get(handles.text1,'String');

textString=strcat(textString,'+');

set(handles.text1,'String',textString)

C. 科学计算函数:

textString=get(handles.text1,'String');

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a=strread(textString, '%f');

a=sin(a);

set(handles.text1,'String',a)

end

D. 退格键:通过取屏幕值,计算出其字符长度,然后取其前N-1项的值来实现退格:

global jj

textString=get(handles.text1,'String');

if(strcmp(textString,'0.')==1)&(jj==0)

set(handles.text1,'String','0.')

else

ss=char(textString);

l=length(textString);

textString=ss(1:l-1);

set(handles.text1,'String',textString)

end jj=0;

E. 清屏键函数:

set(handles.text1,'String','0.')

4.3 各模块实现结果

A. 数字键:

MATLAB课程设计报告

B. 四则运算函数:

MATLAB课程设计报告

MATLAB课程设计报告

经过计算,这些结果均与实际结果相吻合,计算器的功能实现的较为完好。 问题和解决方法:

a. 小数点可以连续输入。解决方法是:用strfind函数查看文本框里有几个小数点,如果已经有一个了,再按小数点就保持不变。

b. 按过运算符号后一个数不等于一个数,比如:输入1,按等号,会出来一个3,经过长时间分析得知,这是由于在按运算符号时,系统记录了文本框里的数但没有清空,才会出现这种问题。解决方法是再申请一个不同于加减乘除的另一个符号,并将按过运算符后记录的数值置0。

五、设计体会

通过本次的MATLAB课程设计,让我对MATLAB尤其是其GUI设计的功能有了进一步的了解,认识到了它功能的强大。在MATLAB简单计算器的设计中,了解了关于MATLAB图形用户界面的部分控件的使用方法;利用MATLAB的GUI提供的很多实用的控件,方便用于设计属于自己的图形界面。

参考文献:

[1]刘卫国编著.MATLAB程序设计与应用(第二版).2006.7

[2]王洪元主编.MATLAB语言及其在电子信息工程中的应用 清华大学出版社 程序清单:

定义函数

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

gui_Singleton',

gui_Singleton, ...

gui_OpeningFcn', @calc_OpeningFcn, ...

gui_OutputFcn', @calc_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 calc is made visible.

function calc_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn.

% hObject handle to figure

% eventdata reserved - to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to calc (see VARARGIN)

% Choose default command line output for calc handles.output = hObject; % Update handles structure guidata(hObject, handles);

% UIWAIT makes calc wait for user response (see UIRESUME)

% uiwait(handles.figure1);

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

jj=0;

% --- Outputs from this function are returned to the command line. function varargout = calc_OutputFcn(hObject, eventdata, handles)

% varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure

% eventdata reserved - to be defined in pushbutton20 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;

按键0响应(按键0-9响应程序一样)

% --- Executes on button press in pushbutton1.

function pushbutton1_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton1 (see GCBO)

%eventdata reserved - to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data(see GUIDATA)

global jj

textString = get(handles.text1,'String');

if(strcmp(textString,'0.')==1)&(jj==0)

set(handles.text1,'String','0')

else

textString =strcat(textString,'0');

set(handles.text1,'String',textString)

end jj=0;

%按键‘/’响应

% --- Executes on button press in pushbutton13.

function pushbutton13_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton13 (see GCBO)

% eventdata reserved-to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

textString =strcat(textString,'/');

set(handles.text1,'String',textString)

%按键‘(’响应

% --- Executes on button press in pushbutton14.

function pushbutton14_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton13 (see GCBO)

% eventdata reserved-to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString = get(handles.text1,'String');

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','(')

else

textString =strcat(textString,'(');

set(handles.text1,'String',textString)

end

%按键‘*’响应

% --- Executes on button press in pushbutton15.

function pushbutton15_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton15 (see GCBO)

% eventdata reserved- to be defined in pushbutton20 future version of MATLAB% handles structure with handles and user data (see GUIDATA) %end textString = get(handles.text1,'String'); textString =strcat(textString,'*'); set(handles.text1,'String',textString)

%按键‘)’响应

% --- Executes on button press in pushbutton16.

function pushbutton16_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton16 (see GCBO)

% eventdata reserved- to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

if(strcmp(textString,'0.')==1)

set(handles.text1,'String',')')

else

textString =strcat(textString,')');

set(handles.text1,'String',textString)

end

%按键‘-’响应

% --- Executes on button press in pushbutton17.

% case '-'

% ans=pushbutton20-c;

% case '+'

% ans=pushbutton20+c;

%

% end ans =eval(textString);

set(handles.text1,'String',ans)

end

%按键‘+’响应

% --- Executes on button press in pushbutton19.

function pushbutton19_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton14 (see GCBO)

% eventdata reserved - to be defined in pushbutton20

future version of MATLAB

% handles structure with handles and user data (see GUIDATA) textString = get(handles.text1,'String');

textString =strcat(textString,'+');

set(handles.text1,'String',textString)

end

%按键‘sin’响应 % --- Executes on button press in pushbutton21.

function pushbutton21_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton21 (see GCBO)

% eventdata reserved - to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=sin(a); set(handles.text1,'String',a)

end

%按键‘cos’响应

% --- Executes on button press in pushbutton22.

function pushbutton22_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton22 (see GCBO)

% eventdata reserved - to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else a = strread(textString, '%f');

a=cos(a); set(handles.text1,'String',a)

end

%按键‘tan’响应

% --- Executes on button press in pushbutton23.

function pushbutton23_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton22 (see GCBO)

% eventdata reserved - to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=tan(a);

set(handles.text1,'String',a)

end

%按键‘log10’响应

% --- Executes on button press in pushbutton24.

function pushbutton24_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton23 (see GCBO)

% eventdata reserved - to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA) textString = get(handles.text1,'String');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=log10(a); set(handles.text1,'String',a)

end

%按键‘sqrt’响应

% --- Executes on button press in pushbutton25.

function pushbutton25_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton24 (see GCBO)

% eventdata reserved - to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=sqrt(a);

set(handles.text1,'String',a)

end

%按键‘+/-’响应

% --- Executes on button press in pushbutton34.

function pushbutton34_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton34 (see GCBO)

% eventdata reserved-to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=0-a;

set(handles.text1,'String',a)

end

% 按键backspace响应

% --- Executes on button press in pushbutton27.

function pushbutton27_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton18 (see GCBO)

% eventdata reserved-to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

global jj

textString = get(handles.text1,'String');

if(strcmp(textString,'0.')==1)&(jj==0)

set(handles.text1,'String','0.')

else

ss=char(textString);

l=length(textString);

textString=ss(1:l-1);

set(handles.text1,'String',textString)

end jj=0;

%按键‘X^2’响应

% --- Executes on button press in pushbutton31.

function pushbutton31_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton2 (see GCBO)

% eventdata reserved - to be defined in pushbutton20 future version of MATLAB % handles structure with handles and user data (see GUIDATA)

textString = get(handles.text1,'String');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=a*a;

set(handles.text1,'String',a)

end

%按键‘C’响应

% --- Executes on button press in pushbutton28.

function pushbutton28_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton28 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

set(handles.text1,'String','0.')

%按键‘cot’响应

% --- Executes on button press in pushbutton30.

function pushbutton30_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton30 (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');

%strcmp(textString,'0.')

if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=cot(a);

set(handles.text1,'String',a)

end

%按键‘log2’响应

% --- Executes on button press in pushbutton48.

function pushbutton48_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton48 (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'); %strcmp(textString,'0.') if(strcmp(textString,'0.')==1)

set(handles.text1,'String','0.')

else

a = strread(textString, '%f');

a=log2(a);

set(handles.text1,'String',a)

end

更多相关推荐:
课程设计报告

1课程设计目的课程设计是船舶设计原理课程重要的实践性教学环节是培养学生掌握船舶设计基本原理和能力的技术基础主尺度论证与总布置设计是船舶总体设计的重要组成部分通过课程设计的训练力求使学生实现从学生到船舶设计师的角...

课程设计报告内容

一设计目的1强化上机动手能力在理论和实践的基础上进一步巩固数据结构课程学习的内容掌握工程化软件设计的基本方法2掌握图的创建和应用3掌握迪杰斯特拉以及Prim等基本算法思想4掌握if语句及switch语句的运用方...

课程设计报告

中国计量学院信息工程学院课程设计报告课程设计名称系统设计与仿真课程计二级学院信息工程学院专业班级10电信2班学姓成绩号名1000301232廖壁波指导老师20xx年12月13日中国计量学院信息工程学院课程设计报...

课程设计报告模板

信息科学与工程学院高级语言程序设计课程设计报告学生成绩管理系统学科专业计算机科学与技术班级1301学号指导教师唐郑熠讲师学生二零年月目录目录1设计任务12需求分析121基础功能122扩展功能13系统概要设计13...

课程设计报告

扬州大学数据结构课程设计报告课题名称姓名学院系科班级指导老师日期自来水管架设问题广陵学院陈宏建1一课程设计的题目自来水管理架设问题问题描述若要在扬州大学的八个居民区A区B区C区D区E区F区G区H区之间架设自来水...

课程设计报告

系统软件课程设计时钟中断与进程调度学号姓名指导教师11070319许明秀金雪云20xx年12月一报告摘要进程调度是操作系统十分重要的一个部分在操作系统的设计过程中进程调度和时钟中断形成了密不可分的关系系统时钟定...

课程设计报告

计算机高级语言课程设计报告班级学号姓名蔡路日期学生成绩管理系统19xx3120xx100031020xx年1月18日一课程设计题目与要求实习题目学生成绩管理系统实习内容C语言面向对象的分析与设计基本要求学生成绩...

JAVA_课程设计报告

JAVA程序设计课程设计报告设计题目学院名称专业班级姓名学号1目录一需求分析3二概要设计3三详细设计331数据库设计332模块及窗体设计3321数据库模块设计3322用户登录识别模块5323用户信息管理模块61...

软件课程设计报告

中南民族大学软件课程设计报告电子信息工程09级题目学生吴雪学号指导教师王锦程电子工程0907100220xx年4月25日简易网络聊天系统摘要计算机网络通信技术已经深入我们的生活并给我们即使通信带来了很大的方随着...

软件课程设计报告

任务书北京信息科技大学计算机软件基础课程设计题目从某个源点到其余各顶点的最短路径学院专业学生姓名班级学号指导老师起止时间任务书1摘要摘要本次课程设计的问题假设西安北京沈阳武汉4个城市构成小型交通网4个城市表示图...

计算机网络课程设计报告

计算机网络课程设计报告一.课程设计的题目、目的及要求.........................................................2二.课程设计的内容(分析和设计).....…

Java课程设计报告模板

Java程序设计课程设计报告20xx20xx年度第1学期Hannio塔专业学生姓名班级学号指导教师完成日期计算机科学技术网络工程马千里B计算机1021010704213徐森20xx年1月8日Hannoi塔目录目...

课程设计报告(33篇)