编写科学计算器,(要求)左右对分,右边上下对分,左边是科学计算器,右上是画函数图像,右下显示任意格式的图片

全部代码在文末百度云链接。

效果如上图所示,需要在设计视图拖入 面板,按钮,坐标区,编辑字段文本,图像,这些组件库

添加按钮1的回调函数

按钮1的回调函数设置,其他按钮类似,只需要改变‘1’里面的值,是2就改成2,是+就改成+

唯一有区别的是等号键,退格键和清空键

等于的思路就是把输出文本框里面的文本转换为数值格式然后用eval函数进行计算然后赋值给文本框。

全部代码如下:

classdef mode < matlab.apps.AppBase% Properties that correspond to app componentsproperties (Access = public)MatlabUIFigure  matlab.ui.FigureLabel_3         matlab.ui.control.LabelButton          matlab.ui.control.ButtonysinxTextArea   matlab.ui.control.TextAreaysinxLabel      matlab.ui.control.LabelPanel           matlab.ui.container.PaneltextString      matlab.ui.control.TextAreaLabel           matlab.ui.control.Labeldengyu          matlab.ui.control.Buttonclc             matlab.ui.control.Buttondian            matlab.ui.control.Buttonzero            matlab.ui.control.Buttonthree           matlab.ui.control.Buttontwo             matlab.ui.control.Buttonone             matlab.ui.control.Buttonjian            matlab.ui.control.Buttonsix             matlab.ui.control.Buttonfive            matlab.ui.control.Buttonfour            matlab.ui.control.Buttonadd             matlab.ui.control.Buttonnigh            matlab.ui.control.Buttoneight           matlab.ui.control.Buttonsiven           matlab.ui.control.Buttontuige           matlab.ui.control.Buttonchengyi         matlab.ui.control.Buttonchuyi           matlab.ui.control.Buttonpingfang        matlab.ui.control.ButtonImage           matlab.ui.control.ImageUIAxes          matlab.ui.control.UIAxesendmethods (Access = private)function results = PlotStep(app,value)%PlotStep函数绘制阶跃响应曲线z=cell2mat(value);     %从编辑框中获取zeta数据,可以是一个数组cla(app.UIAxes)ezplot(app.UIAxes,z);      %绘制曲线endend% Callbacks that handle component eventsmethods (Access = private)% Code that executes after component creationfunction startupFcn(app)addpath('image\');value = app.ysinxTextArea.Value;PlotStep(app,value);   %调用函数PlotStep绘制end% Button pushed function: onefunction oneButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'1');app.textString.Value=text;end% Button pushed function: twofunction twoButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'2');app.textString.Value=text;end% Button pushed function: threefunction threeButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'3');app.textString.Value=text;end% Button pushed function: fourfunction fourButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'4');app.textString.Value=text;end% Button pushed function: fivefunction fiveButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'5');app.textString.Value=text;end% Button pushed function: sixfunction sixButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'6');app.textString.Value=text;end% Button pushed function: sivenfunction sivenButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'7');app.textString.Value=text;end% Button pushed function: eightfunction eightButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'8');app.textString.Value=text;end% Button pushed function: nighfunction nighButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'9');app.textString.Value=text;end% Button pushed function: zerofunction zeroButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'0');app.textString.Value=text;end% Button pushed function: dianfunction dianButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'.');app.textString.Value=text;end% Button pushed function: chuyifunction chuyiButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'/');app.textString.Value=text;end% Button pushed function: chengyifunction chengyiButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'*');app.textString.Value=text;end% Button pushed function: addfunction addButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'+');app.textString.Value=text;end% Button pushed function: jianfunction jianButtonPushed(app, event)text =app.textString.Value;text =strcat(text,'-');app.textString.Value=text;end% Button pushed function: dengyufunction dengyuButtonPushed(app, event)text =app.textString.Value;text=cell2mat(text)%转变变量格式ans=eval(text)ans1=num2str(ans);app.textString.Value=ans1;end% Button pushed function: clcfunction clcButtonPushed(app, event)app.textString.Value=' ';end% Button pushed function: tuigefunction tuigeButtonPushed(app, event)text = app.textString.Value;text=cell2mat(text);n=length(text);t=char(text);text=t(1:n-1);app.textString.Value=text;end% Button pushed function: pingfangfunction pingfangButtonPushed(app, event)text =app.textString.Value;text=cell2mat(text)%转变变量格式ans = eval(text)ans=ans*ans;ans1=num2str(ans);app.textString.Value=ans1;end% Callback functionfunction Button_2Pushed(app, event)files_path = './image/';  nm=randperm(8,1);nm=num2str(nm);text =[nm,'.jpg'];text1 =[files_path,nm,'.jpg'];app.EditField_2.Value=text;app.Image.ImageSource=text1;end% Button pushed function: Buttonfunction ButtonPushed(app, event)value = app.ysinxTextArea.Value;PlotStep(app,value);   %调用函数PlotStep绘制end% Callback functionfunction PushTool4Clicked(app, event)end% Callback functionfunction MatlabMenuSelected(app, event)end% Callback functionfunction PushTool5Clicked(app, event)app.MatlabUIFigure.Color=[0.65 0.65 0.65];end% Callback functionfunction PushTool6Clicked(app, event)app.MatlabUIFigure.Color=[1 1 1];endend% Component initializationmethods (Access = private)% Create UIFigure and componentsfunction createComponents(app)% Create MatlabUIFigure and hide until all components are createdapp.MatlabUIFigure = uifigure('Visible', 'off');app.MatlabUIFigure.Color = [1 1 1];app.MatlabUIFigure.Position = [100 100 733 500];app.MatlabUIFigure.Name = 'Matlab计算器';app.MatlabUIFigure.Icon = '4_1.png';% Create UIAxesapp.UIAxes = uiaxes(app.MatlabUIFigure);title(app.UIAxes, '简单函数图形')app.UIAxes.XTick = [];app.UIAxes.YTick = [];app.UIAxes.XGrid = 'on';app.UIAxes.YGrid = 'on';app.UIAxes.Box = 'on';app.UIAxes.Position = [406 294 281 196];% Create Imageapp.Image = uiimage(app.MatlabUIFigure);app.Image.BackgroundColor = [1 1 1];app.Image.Position = [405 43 280 196];app.Image.ImageSource = '4.jpg';% Create Panelapp.Panel = uipanel(app.MatlabUIFigure);app.Panel.Title = '简易科学计算器';app.Panel.BackgroundColor = [0.902 0.902 0.902];app.Panel.Position = [31 68 347 409];% Create pingfangapp.pingfang = uibutton(app.Panel, 'push');app.pingfang.ButtonPushedFcn = createCallbackFcn(app, @pingfangButtonPushed, true);app.pingfang.Position = [12 258 71 34];app.pingfang.Text = 'X^2';% Create chuyiapp.chuyi = uibutton(app.Panel, 'push');app.chuyi.ButtonPushedFcn = createCallbackFcn(app, @chuyiButtonPushed, true);app.chuyi.Position = [99 258 71 34];app.chuyi.Text = '➗';% Create chengyiapp.chengyi = uibutton(app.Panel, 'push');app.chengyi.ButtonPushedFcn = createCallbackFcn(app, @chengyiButtonPushed, true);app.chengyi.Position = [187 258 71 34];app.chengyi.Text = {'✖'; ''};% Create tuigeapp.tuige = uibutton(app.Panel, 'push');app.tuige.ButtonPushedFcn = createCallbackFcn(app, @tuigeButtonPushed, true);app.tuige.Position = [270 258 71 34];app.tuige.Text = '退格';% Create sivenapp.siven = uibutton(app.Panel, 'push');app.siven.ButtonPushedFcn = createCallbackFcn(app, @sivenButtonPushed, true);app.siven.Position = [13 208 71 34];app.siven.Text = '7';% Create eightapp.eight = uibutton(app.Panel, 'push');app.eight.ButtonPushedFcn = createCallbackFcn(app, @eightButtonPushed, true);app.eight.Position = [100 208 71 34];app.eight.Text = '8';% Create nighapp.nigh = uibutton(app.Panel, 'push');app.nigh.ButtonPushedFcn = createCallbackFcn(app, @nighButtonPushed, true);app.nigh.Position = [188 208 71 34];app.nigh.Text = '9';% Create addapp.add = uibutton(app.Panel, 'push');app.add.ButtonPushedFcn = createCallbackFcn(app, @addButtonPushed, true);app.add.Position = [271 208 71 34];app.add.Text = '➕';% Create fourapp.four = uibutton(app.Panel, 'push');app.four.ButtonPushedFcn = createCallbackFcn(app, @fourButtonPushed, true);app.four.Position = [15 161 71 34];app.four.Text = '4';% Create fiveapp.five = uibutton(app.Panel, 'push');app.five.ButtonPushedFcn = createCallbackFcn(app, @fiveButtonPushed, true);app.five.Position = [100 161 71 34];app.five.Text = '5';% Create sixapp.six = uibutton(app.Panel, 'push');app.six.ButtonPushedFcn = createCallbackFcn(app, @sixButtonPushed, true);app.six.Position = [188 161 71 34];app.six.Text = '6';% Create jianapp.jian = uibutton(app.Panel, 'push');app.jian.ButtonPushedFcn = createCallbackFcn(app, @jianButtonPushed, true);app.jian.Position = [271 161 71 34];app.jian.Text = '➖';% Create oneapp.one = uibutton(app.Panel, 'push');app.one.ButtonPushedFcn = createCallbackFcn(app, @oneButtonPushed, true);app.one.Position = [14 111 71 34];app.one.Text = '1';% Create twoapp.two = uibutton(app.Panel, 'push');app.two.ButtonPushedFcn = createCallbackFcn(app, @twoButtonPushed, true);app.two.Position = [101 111 71 34];app.two.Text = '2';% Create threeapp.three = uibutton(app.Panel, 'push');app.three.ButtonPushedFcn = createCallbackFcn(app, @threeButtonPushed, true);app.three.Position = [189 111 71 34];app.three.Text = '3';% Create zeroapp.zero = uibutton(app.Panel, 'push');app.zero.ButtonPushedFcn = createCallbackFcn(app, @zeroButtonPushed, true);app.zero.Position = [13 64 71 34];app.zero.Text = '0';% Create dianapp.dian = uibutton(app.Panel, 'push');app.dian.ButtonPushedFcn = createCallbackFcn(app, @dianButtonPushed, true);app.dian.Position = [100 64 71 34];app.dian.Text = '.';% Create clcapp.clc = uibutton(app.Panel, 'push');app.clc.ButtonPushedFcn = createCallbackFcn(app, @clcButtonPushed, true);app.clc.Position = [188 64 71 34];app.clc.Text = '清空';% Create dengyuapp.dengyu = uibutton(app.Panel, 'push');app.dengyu.ButtonPushedFcn = createCallbackFcn(app, @dengyuButtonPushed, true);app.dengyu.Position = [273 65 67 79];app.dengyu.Text = '=';% Create Labelapp.Label = uilabel(app.Panel);app.Label.HorizontalAlignment = 'right';app.Label.Position = [16 366 41 22];app.Label.Text = '显示器';% Create textStringapp.textString = uitextarea(app.Panel);app.textString.Position = [38 329 246 38];% Create ysinxLabelapp.ysinxLabel = uilabel(app.MatlabUIFigure);app.ysinxLabel.HorizontalAlignment = 'right';app.ysinxLabel.Position = [392 286 131 22];app.ysinxLabel.Text = '输入函数(如y=sin(x))';% Create ysinxTextAreaapp.ysinxTextArea = uitextarea(app.MatlabUIFigure);app.ysinxTextArea.Position = [521 282 175 25];app.ysinxTextArea.Value = {'y=sin(x)'};% Create Buttonapp.Button = uibutton(app.MatlabUIFigure, 'push');app.Button.ButtonPushedFcn = createCallbackFcn(app, @ButtonPushed, true);app.Button.Position = [405 262 100 25];app.Button.Text = '生成函数图形';% Create Label_3app.Label_3 = uilabel(app.MatlabUIFigure);app.Label_3.Position = [528 241 29 22];app.Label_3.Text = '图片';% Show the figure after all components are createdapp.MatlabUIFigure.Visible = 'on';endend% App creation and deletionmethods (Access = public)% Construct appfunction app = mode% Create UIFigure and componentscreateComponents(app)% Register the app with App DesignerregisterApp(app, app.MatlabUIFigure)% Execute the startup functionrunStartupFcn(app, @startupFcn)if nargout == 0clear appendend% Code that executes before app deletionfunction delete(app)% Delete UIFigure when app is deleteddelete(app.MatlabUIFigure)endend
end

链接:https://pan.baidu.com/s/1WEnvBsEXo9mN-R4TpSQilQ 
提取码:3344

MATLAB 计算器,函数图形绘制,图片展示 APP Designer 版本相关推荐

  1. 【MATLAB】三维图形绘制 ( 绘制网格 + 等高线 | meshc 函数 | 绘制平面 + 等高线 | surfc 函数 )

    文章目录 一.绘制网格 + 等高线 1.meshc 函数 2.代码示例 二.绘制平面 + 等高线 1.surfc 函数 2.代码示例 一.绘制网格 + 等高线 1.meshc 函数 meshc 函数参 ...

  2. MatLab中函数图形的绘制

    原文地址为: MatLab中函数图形的绘制 在MatLab中绘制函数图形,可以使用Plot函数,下面使用该函数绘制二次函数曲线. x=[-5:0.1:5]; y=x.^2; %注意这里必须使用点乘. ...

  3. 用matlab画出ex,如何用matlab画函数图形

    1.首先打开matlab应用程序,输入下方的代码:2.然后按确定会出现一张图,如下图所示,这就是 怎么用matlab画函数图形?请看下面方法. 方法 打开Matlab. r0=5;b=1;t0=2;s ...

  4. MATLAB二维图形绘制

    MATLAB二维图形绘制 数据点标记 数据点 颜色 线型 曲线图 一.plot函数 (一)最简单的plot函数调用格式: plot(x) (1)plot函数的参数 X 为普通向量, (2)plot函数 ...

  5. matlab一般函数的绘制方法,基于MATLAB的函数图像绘制方法

    C DOI:10.16707~.cnki.fjpc.2017.01.084 E 晒 亍嚣 基于 MATLAB的函数图像绘制方法 张笑笑 一,童 键 z (1湖南省长沙市第一中学 湖南 长沙 410() ...

  6. Matlab二维图形绘制与图形处理

    Matlab二维图形绘制与图形处理 一.二维图形绘制 1.极坐标图 2.散点图 3. 平面等值线图 二.图形处理 1.添加格栅,图例 和标注 2.定制坐标 3.在之前基础上继续作图 4.新建图形置于当 ...

  7. C语言 函数图形绘制系统

    系统功能简述: 初等函数曲线图形的简易绘制:设屏幕显示文本是25行, 80列,可以用"+"和"--〉"号画坐标系,用"*"号画曲线上的点.用 ...

  8. matlab中rastrigin图形绘制,matlab函数function

    x?6 x?6 (1) 利用MATLAB语言编写S函数.程序如下: function [sys,x0,str,ts]=sfunction(t,x,u,flag) switch flag, case 0 ...

  9. matlab中三维图形绘制函数

    1.plot3 plot3是最基本的三维图形函数,它将二维plot函数的功能拓展到三维空间,其基本的调用格式为plot3(x1,y1,z1,'图形设置选项1',x2,y2,z2,'图形设置选项2'-- ...

最新文章

  1. Go语言开发常见陷阱,你遇到过几个?
  2. PCIE 硬件接口那点屁事
  3. 使用 DES 算法对数据加密
  4. 操作系统四: 内存连续分配
  5. 网络公开课资源 ——关注CS/AI/Math
  6. oracle中sequence详解
  7. CAD2010 为了保护_一文弄懂,锂电池的充电电路,以及它的保护电路方案设计
  8. Cortex-M3 I-Code,D-Code,系统总线及其他总线接口
  9. 生成随机序列的算法c语言,一个C语言编写的不重复随机序列算法
  10. 计算机基础类报刊,全国“xx杯”计算机应用基础类说课大赛优秀作品:图文表混排-制作感恩报刊说课课件...
  11. 贪心----多元Huffman编码问题
  12. 【追寻javascript高手之路05】理解事件流
  13. 0.《JavaScript高级程序设计》(Nicholas C.Zakas 第3版)
  14. 什么是云渲染?为什么要用电脑渲图?
  15. “三行情书”——给你三行代码的爱恋~
  16. 币图网以太坊开发实例_去中心化概念模型与架构设计
  17. The server is invalid. Error occurred reading server credential. Required file or directory ‘serverO
  18. 使用 Abp.Zero 搭建第三方登录模块(四):微信小程序开发
  19. 传奇GOM/GEE微端配置外网架设教程
  20. c语言 北京时间转换utc时间_UTC时间转换成北京时间C语言函数代码

热门文章

  1. 自助建站与智能建站有什么特点
  2. Intellij IDEA使用破解补丁激活(最新)
  3. 外贸公司报价/换汇成本计算公式
  4. python爬人人贷代码视频_Python爬虫 - 人人贷散标
  5. 为什么说国际站要做长尾词排名?
  6. Dungeon Master POJ - 2251
  7. js 正则 验证手机号码
  8. Exception in thread “main“ java.lang.NoClassDefFoundError: org/apache/velocity/context/Contex
  9. Oracle删除带有默认值的字段
  10. 知其然更要知其所以然,聊聊SQLite软件架构