matlab图形句柄+图形对象+图形对象的属性+对象操作

文章目录

      • 前言:
      • 图形对象:
      • 图形句柄:
      • 图形对象的属性:
      • 对象的基本操作
      • figure对象(图形窗口)
        • figure()函数:
        • clf()函数清空当前图形窗口:
      • axes坐标轴对象
      • image()
      • line()
      • text()

前言:

下面这些是为了更好地写回调函数。例子我后面会整出来,都是可以在gui里面整的,非常强,先罗列一下基本知识及定义。

图形对象:

Matlab中,把用于数据可视化和界面制作的基本绘图要素称为图形对象。每一个具体的图形都是由若干不同的图形对象构成。

图形句柄:

matlab在创建每一个图形对象时,都为该对象分配唯一的一个值, 称其为图形对象句柄。句柄是图形对象的唯一标识符,不同对象的句柄不可 能重复和混淆

计算机屏幕作为根对象(root)由 系统自动建立,其句柄值为0。而图形窗口对象(figure)的句柄值为一正整数,并显示在该窗口的标题栏。其他图形对象的句柄为浮点数。

MATLAB在创建各种对象时,会产生该对象的句柄,通过句柄可以实现对该对象的各种控制和设置

MATLAB提供了若干个函数用于获取已有图形对象的句柄。

图形对象的属性:

图形对象的属性是 一些特殊值,可以对图形对象进行控制和设置。每个属性都有一个属性名和属性值。
属性名通常是采用大小写字母组成的字符串,第一个字母大写。但是在MATLAB中,图形对象的属性名不区分大小写。

用户可以在创建图形对象时,对属性值进行设置。如果用户没有对属性值进行设置,则所有的属性都会自动初始化为系统的默认值。例如figure(‘Toolbar’,‘none’,‘Menubar’‘none’),将创建没有工具栏和菜单的图形窗口。

图形对象的属性非常多,通常在创建图形对象后,通过句柄对属性值进行修改。利用函数ge()获取图形对象的属性值,通过函数set()设置图形对象的属性值

对象的基本操作

获取当前图形对象的函数:

函数说明
gcf()获取当前图形窗口的句柄
gca()获取当前图形窗口中坐标轴的句柄
gco()获取当前图形窗口中当前对象的句柄
gcbf()获取正在执行的回调程序对应的对象所在窗口的句柄
gcbo()获取正在执行的回调程序对应的图像句柄

除了get()和set()获取和设置图形对象的属性之外,还可以有其他操作:

函数说明
reset()对象的复位,恢复为默认值
findobj()对象的查找
findall()查找所有对象,包括隐藏的对象
copyobj()对象的复制
delete()对象的删除
allchild()查找所有的子对象
ancestor()查找对象的父对象

figure对象(图形窗口)

figure()函数:

Syntax

figure
figure('PropertyName',propertyvalue,...)
figure(h)
h = figure(...)

Description

figure creates a new figure window using default property values. This new figure window becomes the current figure, and it displays on top of all other figures on the screen. The title of the figure is an integer value that is not already used by an existing figure. MATLAB® saves this integer value in the figure’s Number property.

figure(‘PropertyName’,propertyvalue,…) creates a new figure window using specific property values. For a list of available properties, see Figure Properties. MATLAB uses default values for any properties that you do not explicitly define as arguments.
创建属性为PropertyName,值为propertyvalue的图形窗口

figure(h) does one of the following:

If h is the handle or the Number property value of an existing figure, then figure(h) makes that existing figure the current figure, makes it visible, and moves it on top of all other figures on the screen. The current figure is the target for graphics output.
If h is not the handle and is not the Number property value of an existing figure, but is an integer, then figure(h) creates a figure object and assigns its Number property the value h.
If h is not the handle to a figure and is not a positive integer, then MATLAB returns an error.

h = figure(…) returns the handle to the figure object.

clf()函数清空当前图形窗口:

只是清空而不关闭,如果关闭图形窗口采用close().
close all关闭所有

Syntax

clf
clf('reset')
clf(fig)
clf(fig,'reset')
figure_handle = clf(...)

Description

clf
deletes from the current figure all graphics objects whose handles are not hidden (i.e., their HandleVisibility property is set to on).

clf(‘reset’)
deletes from the current figure all graphics objects regardless of the setting of their HandleVisibility property and resets all figure properties except Position, Units, PaperPosition, and PaperUnits to their default values.

clf(fig) or clf(fig,‘reset’)
clears the single figure with handle fig.
清除窗口fig中所有不隐藏的对象

figure_handle = clf(…)
returns the handle of the figure. This is useful when the figure IntegerHandle property is off because the noninteger handle becomes invalid when the reset option is used (i.e., IntegerHandle is reset to on, which is the default).

例子:

figure;
t=-pi:pi/20:pi;
plot(t,cos(t),'r');%绘制曲线
pause(3);
clf(gcf);%清空图形窗口内容
pause(3);
close(gcf);%关闭图形窗口

axes坐标轴对象

Syntax

axes
axes('PropertyName',propertyvalue,...)
axes(parent,...)
axes(h)
h = axes(...)

Description

axes creates an axes graphics object in the current figure using default property values. axes is the low-level function for creating axes graphics objects. MATLAB® automatically creates an axes, if one does not already exist, when you issue a command that creates a graph.

axes(‘PropertyName’,propertyvalue,…) creates an axes object having the specified property values. For a description of the properties, see Axes Properties. MATLAB uses default values for any properties that you do not explicitly define as arguments. The axes function accepts property name/property value pairs, structure arrays, and cell arrays as input arguments (see the set and get commands for examples of how to specify these data types). While the basic purpose of an axes object is to provide a coordinate system for plotted data, axes properties provide considerable control over the way MATLAB displays data.

axes(parent,…) creates the axes in the figure, uipanel, or uitab specified by parent, instead of in the current figure.

axes(h) makes existing axes h the current axes and brings the figure containing it into focus. It also makes h the first axes listed in the figure’s Children property and sets the figure’s CurrentAxes property to h. The current axes is the target for functions that draw image, line, patch, rectangle, surface, and text graphics objects.

If you want to make an axes the current axes without changing the state of the parent figure, set the CurrentAxes property of the figure containing the axes:

set(figure_handle,‘CurrentAxes’,axes_handle)
This command is useful if you want a figure to remain minimized or stacked below other figures, but want to specify the current axes.

h = axes(…) returns the handle of the created axes object.

Use the set function to modify the properties of an existing axes or the get function to query the current values of axes properties. Use the gca command to obtain the handle of the current axes.

The axis (not axes) function provides simplified access to commonly used properties that control the scaling and appearance of axes.

Set default axes properties on the figure and root levels:

set(groot,‘DefaultAxesPropertyName’,PropertyValue,…)
set(gcf,‘DefaultAxesPropertyName’,PropertyValue,…)
PropertyName is the name of the axes property and PropertyValue is the value you are specifying. Use set and get to access axes properties.

利用函数gca可以获取当前坐标轴的句柄,因此,利用get(gca)可获取当前坐标轴的属性。通过函数set(gca,‘PropertyName’,‘PropertyValue’)可以对坐标轴的属性进行设置

例子:

figure;
h=axes;
set(h,'Color',[1 0 0]);
set(h,'Units','Centimeters');

image()

clear all;
close all;
A=imread('C:\Users\***\Desktop\dogg.png','png');
A=im2double(A);
h=image(A);%高级调用
set(gca,'xlim',[0 500],'ylim',[0 400]);
get(h,'type');

在这里插入图片描述

clear all;
close all;
A=imread('C:\Users\***\Desktop\dogg.png','png');
A=im2double(A);
h=image('CData',A);%采用CData属性进行图像显示
set(gca,'xlim',[0 500],'ylim',[0 400]);
get(h,'type');

在这里插入图片描述

加一个set(gca,‘ydir’,‘reverse’)可将坐标轴y轴反向,从而使两幅图相同

line()

为了方便,我直接做成表格了

SyntaxDescription
line
line(X,Y)绘制二维曲线
line(X,Y,Z)绘制三维曲线
line(X,Y,Z,‘PropertyName’,propertyvalue,…)对线条对象的属性进行设置
line(‘XData’,x,‘YData’,y,‘ZData’,z,…)
line(ax,…)
h = line(…)返回线条对象的句柄

例子:

clear all;
close all;
t=0:pi/20:pi;
x=sin(t);
y=cos(t);
z=sin(t).*cos(t);
h=line(x,y,z);%线条对象
set(h,'LineWidth',2,'color',[1 0 0]);%设置属性值
view(3);%改变视角
set(gca,'xgrid','on','ygrid','on','zgrid','on');%设置网格
set(gcf,'position',[200,200,400,400]);%设置图形窗口位置和大小

此外还可通过LineStyle设置线条类型,Marker设置数据点的标记类型,Markersize设置标记点的大小

结果:
在这里插入图片描述

text()

SyntaxDescription
text(x,y,str)在当前坐标轴中的位置(x,y)显示字符串string
text(x,y,z,str)在三维坐标轴中的位置(x,y,z)显示字符串string
text(___,Name,Value)对文本对象的属性进行设置
text(ax,___)
t = text(___)返回text文本对象的句柄

例子:

clear all;
close all;
h1=text(0.3,0.5,'hi,my friend');
set(h1,'Color',[1 0 0]);
h2=text(0.5,0.8,'hi,my friend');
set(h2,'FontSize',14);
set(h2,'BackgroundColor',[0 1 0]);
h3=text(0.6,0.1,'hi,my friend','FontSize',13);
set(h3,'rotation',90);

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/560631.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

linux用户开放crontab权限,linux – / etc / crontab权限

/ etc / crontab文件具有以下权限:-rw-R – R–我知道这个文件是用于系统cron作业的,其他用户不应该有权修改它.当前权限允许所有用户读取对文件的访问权限,使他们能够查看内容.是否有必要让所有用户都能读取/ etc / crontab?我相信所有用户都不应该知道…

echart 高度 不用 不撑满_注意厨房台面高度及细节 装出省心舒服 装出事半功倍...

厨房的装修设计最好还是细节做得好,细节做得能达到事半功倍的效果,厨房台面高度如何设计才是最合适呢?我们一起走进包头装修网了解一下吧!下面三个台面的设计细节,也许就能让你家的厨房突然变得好用起来——哪怕你可能…

利用matlab guide制作简易计算器

前言: 当然了这个太简单了,新手可以借鉴一下,举一反三的话还可以添加一些功能或者简洁一些。比如下拉框啊之类的 而且呢,这个你弄明白了,所有运算有关的,输入输出有关的,都大致相同。 实现过程…

linux复制目录命令夹,linux复制目录(文件夹)和打包命令

linux复制目录(文件夹)和打包命令复制目录命令: cp 需要复制的目录 -r 目的目录 (注意带参数-r)压缩文件:zip -r 压缩后文件名 需要压缩的目录喎?http://www.Bkjia.com/kf/ware/vc/" target"_blank" class"keylink">vcD4KP…

c#怎么拟合函数得到参数_吴恩达老师课程笔记系列第32节 -正则化之代价函数(2)...

第32节 -正则化之代价函数(2)参考视频: 7 - 2 - Cost Function (10 min).mkv 上面的回归问题中如果我们的模型是:我们可以从之前的事例中看出,正是那些高次项导致了过拟合的产生,所以如果我们能让这些高次项的系数接近于 0 的话,我…

Matlab guide菜单+快捷菜单的使用

菜单选择: Opening函数: openingFcn执行于窗口可见之前,这个时候你想做什么的话可以把代码写进去 function plott_OpeningFcn(hObject, eventdata, handles, varargin) t1/200:1/200:1; plot(t,sin(2*pi*t*10),r);几个回调函数: …

linux include 编译,linux-如何使用OpenSSL include编译.c文件?

linux-如何使用OpenSSL include编译.c文件?我正在尝试编译一个包含以下内容的小.c文件:#include #include #include #include 在我拥有.c文件的同一文件夹中,我拥有带有所有这些文件(以及更多文件)的/ openssl,也在突触包管理器中…

c向文件中插入数据_如何把数据写入顺序文件中,VBA代码中Write#语句的利用

大家好,我们今日继续讲解VBA代码解决方案的第132讲内容:使用 Write #语句把数据写入打开顺序文件中。在上一讲的内容中我们讲了打开一文本文件来写入数据的两种方法有:Append或Output,那么问题来了,如何往打开的文件中…

JavaScript变量声明+数据类型+数字格式+操作符+进制

文章目录1.那些高大上的概念术语都是指什么什么是web应用?什么是前台后台?怎么做网页界面呢?JavaScript可以应用到什么上面?2.JavaScript实例:3.语言基础变量声明数据类型基本数据类型:引用数据类型&#x…

linux查看帮助文档的命令,Linux如何使用查看一个命令的帮助文档呢?

摘要:下文讲述Linux操作系统中查看命令的帮助文档的方法分享,如下所示;实现思路:使用 --help命令即可查看命令自带的帮助文档信息例:查看ls命令的帮助信息[rootlocalhost test]# ls --helpUsage: ls [OPTION]... [FILE]...List information about the FI…

python如何更改entry属性_如何在Python3中更改Gtk3 Entry文本颜色?

我在我的应用程序中有一个Gtk.Entry()列表,我想改变其中一些文本的颜色.我尝试了以下方法:#!/usr/bin/python3# Filename: mywindow.pyfrom gi.repository import Gtkfrom gi.repository import Gdkclass MyWindow(Gtk.Window):def __init__(self):Gtk.Window.__ini…

linux 磁盘簇,linux系统exec簇工作原理

操作系统是一个用来和硬件打交道并为用户程序提供一个有限服务集的低级支撑软件。一个计算机系统是一个硬件和软件的共生体,它们互相依赖,不可分割。计算机的硬件,含有外围设备、处理器、内存、硬盘和其他的电子设备组成计算机的发动机。但是…

JavaScript 函数定义+内置函数使用+array对象+object类型

文章目录函数定义random()setInterval()setTimeout()数组对象object函数定义 两种格式: function 自定义函数名称(参数1,参数2,...,参数n){ //函数体 return 返回值; }函数表达式写法(匿名函数)&#xff…

jmeter进程和线程的区别_一文搞懂进程和线程的区别

计算机系统是由硬件和软件组成的,它们共同协作以运行应用程序。先来看下面这张一个典型的计算机系统的硬件组成图从上图中看出一个系统由 CPU、ALU(算术逻辑单元)、PC(程序计数器)、总线(贯穿整个系统的一组电子管道)、IO设备、主存等组成。这些硬件的管理都是由操作…

linux中split函数用法,Linux csplit 命令用法详解-Linux命令大全(手册)

csplitLinux csplit命令用于分割文件。将文件依照指定的范本样式予以切割后,分别保存成名称为xx00,xx01,xx02…的文件。若给予的文件名称为”-“,则csplit指令会从标准输入设备读取数据。语法csplit [-kqsz][-b][-f][-n][--help][--version][文件][范本样…

BOM+DOM+JavaScript读取与操作网页对象

DOM 网页的元素有多种定义方式,那我们怎么描述或指定页面上某个元素呢。为了统一方式,产生了document object model 标准 以HTML表单为例, 文本字段前面的标题由label标签声明 每个表单字段都通过id属性设置唯一的识别名称,用于让…

datax 导入数据中文乱码_DataX在有赞大数据平台的实践

文| 小木 on 大数据一、需求有赞大数据技术应用的早期,我们使用 Sqoop 作为数据同步工具,满足了 MySQL 与 Hive 之间数据同步的日常开发需求。随着公司业务发展,数据同步的场景越来越多,主要是 MySQL、Hive 与文本文件之间的数据同…

网页中嵌入JavaScript+事件触发程序

嵌入方式&#xff1a; 1.JavaScript代码与HTML写在同一个文档中 JavaScript代码要放在<script>和</script>标签之间 而且整个JavaScript代码最好放在</body>前&#xff0c;这样可以让浏览器先加载并显示主体 2.JavaScript代码单独存成.js文件&#xff0c;…

linux查看分区树形状态,查看Linux磁盘的分区状态(lsblk、blkid、parted)

②磁盘的管理是一个相当重要的环节&#xff0c;如果你想在系统里面新增一块磁盘&#xff0c;应该做一下几个操作2.命令格式lablk [选项] [设备文件名]3.选项-d&#xff1a;仅列出磁盘本身&#xff0c;并不会列出该磁盘的分区信息-f&#xff1a;同时列出该磁盘内的文件系统名称-…

sql相同顺序法和一次封锁法_数学专题 | Ep01 隔板法的妙用

数学专题(一) 隔板法的妙用浓度常见哪些问题?排列组合分堆&#xff1f;涂色&#xff1f;到底掌握透彻了吗&#xff1f;解析几何与韦达定理&#xff1f;公式总是记不住&#xff1f;应用题还不会解&#xff1f;除了写作(写作听我的)、逻辑(逻辑说)专题外&#xff0c;本周起我们也…