Matlab课程设计(GUI)——绘制任意函数图

这篇具有很好参考价值的文章主要介绍了Matlab课程设计(GUI)——绘制任意函数图。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

项目名称:matlabGUI设计——函数图像绘制

matlabgui里绘制函数,matlab,课程设计

matlabgui里绘制函数,matlab,课程设计

项目简介

MATLAB GUI 编程是一个功能强大的工具,可以帮助我们构建交互式的用户界面并处理用户输入。通过获取编辑框对象的文本内容、设置图形属性和绘制函数图形,实现了按下按钮事件绘制图像的功能。

功能特点

-可视化绘制

-有平面和立体图像

-可自定范围

-自由度极高

-可二次开发

使用方法

1.打开matlab gui

在matlab命令行窗口输入"guide",敲下回车,选择打开现有gui,选择fig文件matlabgui里绘制函数,matlab,课程设计matlabgui里绘制函数,matlab,课程设计

点击打开,出现gui编辑框

matlabgui里绘制函数,matlab,课程设计

然后再点击运行,就可以看到输入框、生成图案的按键啦

 matlabgui里绘制函数,matlab,课程设计

2.获取用户输入

回调函数可以通过获取编辑框对象的文本内容,获得用户在界面中输入的数据。这使得我们能够在按钮按下事件中获取用户输入的值,用于进一步的处理和计算。

此时我们在输入解析式这边输入我们想要绘制的函数:我们以x^2+y^2=4为例,绘制图像

注:我是直接默认输入的解析式=0了,所以我们输入x^2+y^2-4

matlabgui里绘制函数,matlab,课程设计

3.修改图形属性

回调函数可以使用 set 函数来修改图形对象的各种属性,如线条颜色、线宽、字体样式等。通过修改这些属性,我们可以实现对图形的定制化显示。

按照这个输入:颜色选红色就输入r。(若是蓝色就输入b,黄色就是y,英文首字母..)然后线宽可以选任意数字,我们以2为例,范围就看你想要多大了。

matlabgui里绘制函数,matlab,课程设计

4.绘制图形

回调函数可以利用 MATLAB 提供的绘图函数(如 ezplot 和 ezmesh)绘制二维或三维的函数图形。这些函数可以根据输入的公式和坐标范围,自动生成具有可视化效果的函数图形,方便用户进行数据分析和可视化。

当进行完上面三个步骤,到这里就只需要点点两个按钮(2D、3D)就可以看到图像啦

matlabgui里绘制函数,matlab,课程设计

最大值点和最小值点功能还没做出来,要是有大佬可以指点就更好啦0.o

程序讲解

二维图像的绘制

pushbutton1_Callback:

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)
fd = get(handles.edit1,'String');  %公式输入框
axes(handles.axes1);
Xmin = get(handles.edit4,'String');
Xmax = get(handles.edit5,'String');
Ymin = get(handles.edit6,'String');
Ymax = get(handles.edit7,'String');

f1 = ezplot(fd,[str2num(Xmin),str2num(Xmax),str2num(Ymin),str2num(Ymax)]);
col = get(handles.edit2,'String');
set(f1,'Color',col);
wid = get(handles.edit3,'String');
set(f1,'LineWidth',str2num(wid));
grid on;

三维图像的绘制:

pushbutton2_Callback:

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)
fd = get(handles.edit1,'String');
axes(handles.axes2);
syms x y z
f=get(handles.edit1,'String');
Xmin = get(handles.edit4,'String');
Xmax = get(handles.edit5,'String');
Ymin = get(handles.edit6,'String');
Ymax = get(handles.edit7,'String');
ezmesh(f,[str2num(Xmin),str2num(Xmax),str2num(Ymin),str2num(Ymax)])
grid on;

完成程序:

function varargout = untitled1(varargin)
% UNTITLED1 MATLAB code for untitled1.fig
%      UNTITLED1, by itself, creates a new UNTITLED1 or raises the existing
%      singleton*.
%
%      H = UNTITLED1 returns the handle to a new UNTITLED1 or the handle to
%      the existing singleton*.
%
%      UNTITLED1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED1.M with the given input arguments.
%
%      UNTITLED1('Property','Value',...) creates a new UNTITLED1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled1_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled1_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help untitled1

% Last Modified by GUIDE v2.5 17-Feb-2023 18:05:36

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled1_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled1_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 untitled1 is made visible.
function untitled1_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)
% varargin   command line arguments to untitled1 (see VARARGIN)

% Choose default command line output for untitled1
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes untitled1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = untitled1_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;



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- 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)
fd = get(handles.edit1,'String');  %公式输入框
axes(handles.axes1);
Xmin = get(handles.edit4,'String');
Xmax = get(handles.edit5,'String');
Ymin = get(handles.edit6,'String');
Ymax = get(handles.edit7,'String');

f1 = ezplot(fd,[str2num(Xmin),str2num(Xmax),str2num(Ymin),str2num(Ymax)]);
col = get(handles.edit2,'String');
set(f1,'Color',col);
wid = get(handles.edit3,'String');
set(f1,'LineWidth',str2num(wid));
grid on;


% --- 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)
fd = get(handles.edit1,'String');
axes(handles.axes2);
syms x y z
f=get(handles.edit1,'String');
Xmin = get(handles.edit4,'String');
Xmax = get(handles.edit5,'String');
Ymin = get(handles.edit6,'String');
Ymax = get(handles.edit7,'String');
ezmesh(f,[str2num(Xmin),str2num(Xmax),str2num(Ymin),str2num(Ymax)])
grid on;



function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end

资源下载

百度网盘:链接:https://pan.baidu.com/s/1WSsJEBMhrM27-qkd1stUEA?pwd=gjbn 
提取码:gjbn

github链接:GitHub - sy0045/matlab-gui: great gui文章来源地址https://www.toymoban.com/news/detail-778529.html

到了这里,关于Matlab课程设计(GUI)——绘制任意函数图的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • MATLAB GUI游戏设计——贪吃蛇

    在MATLAB App Designer中创建一个新的App时,我们首先需要设计游戏的界面布局。贪吃蛇游戏通常需要一个网格来作为游戏空间,以及一些控制按钮和信息显示。以下是创建界面布局的步骤: 1. 创建20*20的网格 在这段代码中,我们首先创建一个面板( uipanel ),它将作为游戏网格

    2024年02月01日
    浏览(43)
  • 基于MATLAB的GUI界面设计流程

    大三上小学期学习了MATLAB的GUI界面设计,感觉挺不错的,这里做个总结! 1、命令行输入“guide”指令,打开GUI面板,选择“新建GUI”、“Blank GUI” (左侧工具栏含有待添加的元素) 2、添加所需要的的元素(一般需要普通按钮、静态文本、普通文本、坐标图、单选按钮等)

    2024年02月01日
    浏览(55)
  • Matlab:利用Matlab软件进行GUI界面设计实现图像的基本操作

    📌数模之路+Matlab 专栏正在持续更新中,案例的原理图解析、各种模块分析💖这里都有哦,同时也欢迎大家订阅专栏,获取更多详细信息哦✊✊✊ ✨个人主页:零小唬的博客主页 🥂欢迎大家 👍点赞 📨评论 🔔收藏 ✨作者简介:20级计算机专业学生一枚,来自宁夏,可能会

    2024年02月06日
    浏览(43)
  • Matlab绘制双纵轴图(yyaxis函数)

    四、更改坐标轴颜色

    2024年01月23日
    浏览(42)
  • MATLAB GUI图形化界面设计计算器

    MATLAB GUI界面设计教程可以帮助用户创建交互式的图形用户界面,以简化与MATLAB程序的交互过程。以下是一个简化的教程,指导你如何进行MATLAB GUI界面设计: 1. 启动GUIDE或App Designer GUIDE :在MATLAB命令窗口中输入 guide 命令,然后按Enter键启动GUIDE。 App Designer :在MATLAB的“Apps”

    2024年04月23日
    浏览(52)
  • 优化MATLAB中quiver函数绘制箭头图或矢量图(1)-MATLAB开发

    Matlab的基本数据单位是矩阵,利用Matlab可以较方便得绘制向量分布图,比如空气流的采样数据;函数的梯度;曲面的法线向量等等。Matlab自带的quiver和quiver3函数可以满足这一需求,但是箭头的箭型较为简单,这里主要目的即是进一步绘制更好看的矢量图。 Matlab中自带的quiv

    2023年04月21日
    浏览(78)
  • Matlab三维折线图绘制–surf 函数的使用

      最近在写毕业论文,整理数据需要绘制一个简单的三维图,简单做个分享! 先上结果图: 最后附上代码: clc,clear,close all; % filename = \\\'outFFE\\\'; % namelist = dir(filename+\\\'*.mat\\\'); % len = length(namelist); x = 5:2:25;% x轴 y = 2:2:12;% y轴 %xy坐标平面对应的z值 z = zeros(length(y),length(x)); z(1,1)=3.

    2024年02月15日
    浏览(42)
  • matlab绘制三角函数乘除法的问题

    普通的,画一个sin(x)或者cos(x)网上一大堆,不说了。 关于绘画y=sin(x)*cos(x),看结论的直接拉到最后就好。前面要说一下解决问题的过程。 我想画一个很复杂的函数,其中包含了三角函数的乘除法。 在matlab中输入上式以后,发现报错。 很奇怪,我并没有矩阵啊。 然后一

    2024年02月12日
    浏览(38)
  • MATLAB 之 二维图形绘制的基本函数和辅助操作

    二维图形是将平面坐标上的数据点连接起来的平面图形。可以采用不同的坐标系,除直角坐标系外,还可以采用对数坐标、极坐标。数据点可以用向量或矩阵形式给出,类型可以是实型或复型。二维曲形的绘制无疑是其他绘图操作的基础。 在 MATLAB 中,基本的绘图函数是 pl

    2024年02月06日
    浏览(54)
  • 第5章附录4:本章函数速查表(MATLAB入门课程)

    ​讲解视频:可以在bilibili搜索《MATLAB教程新手入门篇——数学建模清风主讲》。​ MATLAB教程新手入门篇(数学建模清风主讲,适合零基础同学观看)_哔哩哔哩_bilibili 本章知识点非常多,也介绍了非常多的内置函数。下面根据函数的功能提供了几张速查表,这能帮助大家快

    2024年02月03日
    浏览(39)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包