uiprogressdlg
创建进度对话框
说明
使用 d
= uiprogressdlg(fig
,Name,Value
)Name,Value
参量指定 ProgressDialog
属性值。可通过属性值控制对话框的外观和行为。例如,您可以在对话框中添加标题或消息,或者指定不确定进度条。
示例
确定进度条
创建一个名为 myprogress1.m
的程序文件,用该文件创建一个图窗和一个进度对话框。更新代码中三个不同点的 Value
和 Message
属性。
function myprogress1 fig = uifigure; d = uiprogressdlg(fig,'Title','Please Wait',... 'Message','Opening the application'); pause(.5) % Perform calculations % ... d.Value = .33; d.Message = 'Loading your data'; pause(1) % Perform calculations % ... d.Value = .67; d.Message = 'Processing the data'; pause(1) % Finish calculations % ... d.Value = 1; d.Message = 'Finishing'; pause(1) % Close dialog box close(d) end
运行该程序以显示进度对话框。
myprogress1
不确定进度条
创建一个名为 myprogress2.m
的程序文件,用该文件创建一个图窗,并在奇异值分解期间显示不确定进度条。
function myprogress2 fig = uifigure; d = uiprogressdlg(fig,'Title','Computing SVD',... 'Indeterminate','on'); drawnow % Do the SVD computation svd(rand(5000)); % close the dialog box close(d) end
将 Indeterminate
属性设置为 'on'
将以动画方式显示进度条,指示不知道预计完成时间。计算完成后,将由 close
函数关闭对话框。
运行该程序以执行奇异值分解并显示进度对话框。
myprogress2
带有取消按钮的确定进度条
创建一个名为 myprogress3.m
的程序文件,用该文件创建一个图窗并显示求 pi 近似值的进度条。
function myprogress3 fig = uifigure; d = uiprogressdlg(fig,'Title','Approximating Pi',... 'Message','1','Cancelable','on'); drawnow % Approximate pi^2/8 as: 1 + 1/9 + 1/25 + 1/49 + ... pisqover8 = 1; denom = 3; valueofpi = sqrt(8 * pisqover8); steps = 20000; for step = 1:steps % Check for Cancel button press if d.CancelRequested break end % Update progress, report current estimate d.Value = step/steps; d.Message = sprintf('%12.9f',valueofpi); % Calculate next estimate pisqover8 = pisqover8 + 1 / (denom * denom); denom = denom + 2; valueofpi = sqrt(8 * pisqover8); end % Close the dialog box close(d) end
将 Cancelable
属性设置为 'on'
将创建默认标签为取消的取消按钮。for
循环中的第一个命令检查 d.CancelRequested
的值,以查看用户是否点击了取消按钮。如果该值为 true
,则程序退出循环。最后,在 for
循环结束或用户取消后,由 close(d)
命令关闭对话框。
运行该程序以求 pi 的近似值并显示进度对话框。
myprogress3
自定义进度对话框外观
使用 HTML 指定自定义图标和格式化消息文本,以修改进度对话框的外观。
创建一个名为 myprogress4.m
的程序文件,用该文件创建一个图窗并显示进度条。将一个图像文件指定为对话框图标,然后指定对话框将其消息文本解释为 HTML。使用 winter
颜色图创建一个 RGB 颜色值矩阵。使用 for
循环来更新进度条值,并通过使用 HTML 标记来格式化和显示消息颜色。在循环完成后关闭对话框。
function myprogress4 fig = uifigure; d = uiprogressdlg(fig,'Icon','peppers.png', ... 'Interpreter','html'); steps = 100; cmap = winter(steps)*100; for step = 1:steps r = num2str(cmap(step,1)); g = num2str(cmap(step,2)); b = num2str(cmap(step,3)); msg = ['<p style=color:rgb(' r '%,' g '%,' b '%)> Calculating... </p>']; d.Message = msg; d.Value = step/steps; pause(0.05); end close(d) end
运行该程序以显示进度对话框。
myprogress4
输入参数
fig
— 目标图窗
Figure
对象
目标图窗,指定为 Figure
对象。图窗必须使用 uifigure
函数创建。
名称-值参数
将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN
,其中 Name
是参量名称,Value
是对应的值。名称-值参量必须出现在其他参量之后,但参量对组的顺序无关紧要。
在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name
引起来。
示例: d = uiprogressdlg(uifigure,'Value',0.25)
注意
此处所列的属性只是一部分。有关完整列表,请参阅 ProgressDialog 属性。
Value
— 完成的部分
0
(默认) | 介于 0
和 1
之间的数字
完成的部分,指定为 0
和 1
之间的数字。当值为 1
时,进度条达到其全长。在代码中的不同位置更改 Value
,以直观指示正在运行的 App 的进度。
数据类型: double
Message
— 消息
''
(默认) | 字符向量 | 字符向量元胞数组 | 字符串数组
消息,指定为字符向量、字符向量元胞数组或字符串数组。消息显示在对话框中进度条的上方。
要显示多行文本,请指定字符向量元胞数组或字符串数组。数组中的每个元素对应一行文本。每个元素中的硬分行(例如 '\n'
)会创建额外的文本行。
示例: d = uiprogressdlg(uifigure,'Message','Calculating result.');
Title
— 标题
''
(默认) | 字符向量 | 字符串标量
标题,指定为字符向量或字符串标量。标题显示在对话框的标题栏中。
示例: d = uiprogressdlg(uifigure,'Title','Calculating');
Indeterminate
— 不确定进度
'off'
(默认) | on/off 逻辑值
不确定进度,指定为 'off'
或 'on'
,或者指定为数值或逻辑值 1
(true
) 或 0
(false
)。值 'on'
等效于 true
,'off'
等效于 false
。因此,您可以使用此属性的值作为逻辑值。该值存储为 matlab.lang.OnOffSwitchState
类型的 on/off 逻辑值。
将此属性设置为 'on'
以显示动画进度条但不提供具体进度信息。此动画适用于计算时长未知的情形。
为防止不确定进度条无限期显示,请在完成计算后调用 close
函数。
Cancelable
— 允许取消
'off'
(默认) | on/off 逻辑值
允许取消,指定为 'off'
或 'on'
,或者指定为数值或逻辑值 1
(true
) 或 0
(false
)。值 'on'
等效于 true
,'off'
等效于 false
。因此,您可以使用此属性的值作为逻辑值。该值存储为 matlab.lang.OnOffSwitchState
类型的 on/off 逻辑值。
值为 'on'
表示在对话框中显示取消按钮。您可以通过指定 CancelText
属性来自定义按钮标签。
当您允许取消时,您必须检查 CancelRequested
属性的值,并在值为 true
时调用 close
函数。否则,对话框将无限期显示。
Interpreter
— 对话框文本解释器
'none'
(默认) | 'tex'
| 'latex'
| 'html'
对话框文本解释器,指定为:
'none'
- 显示字面字符。'tex'
- 使用 TeX 标记的子集解释文本。'latex'
- 使用 LaTeX 标记子集解释文本。'html'
- 使用 HTML 标记子集解释文本。
TeX 标记
使用 TeX 标记添加上标和下标,并在文本中包含特殊字符。
修饰符会一直作用到文本结尾,但上标和下标除外,因为它们仅修饰下一个字符或花括号中的字符。当您将解释器设置为 'tex'
时,支持的修饰符如下所示。
修饰符 | 描述 | 示例 |
---|---|---|
^{ } | 上标 | 'text^{superscript}' |
_{ } | 下标 | 'text_{subscript}' |
\bf | 粗体 | '\bf text' |
\it | 斜体 | '\it text' |
\sl | 伪斜体(通常与斜体相同) | '\sl text' |
\rm | 常规字体 | '\rm text' |
\fontname{ | 字体名称 - 将 替换为字体系列的名称。您可以将此说明符与其他修饰符结合使用。 | '\fontname{Courier} text' |
\fontsize{ | 字体大小 - 将 替换为以磅为单位的数值标量值。 | '\fontsize{15} text' |
\color{ | 字体颜色 - 将 替换为以下颜色之一:red 、green 、yellow 、magenta 、blue 、black 、white 、gray 、darkGreen 、orange 或 lightBlue 。 | '\color{magenta} text' |
\color[rgb]{specifier} | 自定义字体颜色 - 将 替换为三元素 RGB 三元组。 | '\color[rgb]{0,0.5,0.5} text' |
下表列出了 'tex'
解释器所支持的特殊字符。
字符序列 | 符号 | 字符序列 | 符号 | 字符序列 | 符号 |
---|---|---|---|---|---|
| α |
| υ |
| ~ |
| ∠ |
| ϕ |
| ≤ |
|
|
| χ |
| ∞ |
| β |
| ψ |
| ♣ |
| γ |
| ω |
| ♦ |
| δ |
| Γ |
| ♥ |
| ϵ |
| Δ |
| ♠ |
| ζ |
| Θ |
| ↔ |
| η |
| Λ |
| ← |
| θ |
| Ξ |
| ⇐ |
| ϑ |
| Π |
| ↑ |
| ι |
| Σ |
| → |
| κ |
| ϒ |
| ⇒ |
| λ |
| Φ |
| ↓ |
| µ |
| Ψ |
| º |
| ν |
| Ω |
| ± |
| ξ |
| ∀ |
| ≥ |
| π |
| ∃ |
| ∝ |
| ρ |
| ∍ |
| ∂ |
| σ |
| ≅ |
| • |
| ς |
| ≈ |
| ÷ |
| τ |
| ℜ |
| ≠ |
| ≡ |
| ⊕ |
| ℵ |
| ℑ |
| ∪ |
| ℘ |
| ⊗ |
| ⊆ |
| ∅ |
| ∩ |
| ∈ |
| ⊇ |
| ⊃ |
| ⌈ |
| ⊂ |
| ∫ |
| · |
| ο |
| ⌋ |
| ¬ |
| ∇ |
| ⌊ |
| x |
| ... |
| ⊥ |
| √ |
| ´ |
| ∧ |
| ϖ |
| ∅ |
| ⌉ |
| 〉 |
| | |
| ∨ |
| 〈 |
| © |
LaTeX 标记
使用 LaTeX 标记来格式化和显示数学表达式、方程和特殊字符。使用美元符号将标记的文本括起来。例如,对于行内模式,使用 '$\int_1^{20} x^2 dx$'
,对于显示模式,使用 '$$\int_1^{20} x^2 dx$$'
。
显示的文本将使用默认的 LaTeX 字体样式。您可以使用 LaTeX 标记来更改字体样式。
MATLAB® 支持大多数标准 LaTeX 数学模式命令。有关详细信息,请参阅支持的 LaTeX 命令。
HTML 标记
使用 HTML 标记显示链接和自定义字体样式。
解释器支持部分 HTML 标记。一般情况下,解释器支持与文本相关的标记和样式。不支持的标记和样式将被忽略。
下表列出了支持的元素和元素属性。
HTML 元素 | 属性 | 描述 |
---|---|---|
a | style , target , href , title | 超链接 |
abbr | style , title | 缩写 |
address | style | 联系信息 |
article | style | 自包含的独立内容 |
aside | style | 与主要内容间接相关的内容 |
b | style | 粗体文本 |
bdi | style , dir | 格式与周围文本方向不同的内容 |
bdo | style , dir | 格式与周围文本方向不同的内容 |
big | style | 比周围文本大一个字体大小级别的文本(在 HTML5 中已弃用) |
blockquote | style , cite | 扩展引用 |
br | 不适用 | 换行符 |
caption | style | 表标题 |
center | style | 水平居中的内容 |
cite | style | 创造性工作的标题 |
code | style | 代码片段 |
col | style , align , valign , span , width | 表中的列 |
colgroup | style , align , valign , span , width | 表中的一组列 |
dd | style | 描述列表中的项或值 |
del | style , datetime | 从文档中删除的文本 |
details | style , open | 文本仅在切换到 'open' 状态时才可见的交互式小组件 |
dl | style | 描述列表 |
dt | style | 描述列表中的项或值 |
em | style | 强调的文本(通常以粗体显示) |
font | style , color , size , face | 具有指定字体属性的文本(在 HTML5 中弃用) |
footer | style | 页脚 |
h1 . h2 , h3 , h4 , h5 , h6 | style | 节标题 - <h1> 是最高级别的标题,<h6> 是最低级别的标题 |
header | style | 介绍性内容 |
hr | style | 主题换行 |
i | style | 偏离周围内容的文本 - 默认以粗体方式呈现 |
ins | style , datetime | 插入文档中的文本 |
li | style | 列表中的项 |
mark | style | 标记或突出显示的文本 |
ol | style | 有序列表 |
p | style | 段落 |
pre | style | 预设格式的文本 |
s | style | 带删除线的文本 |
strike | style | 带删除线的文本(在 HTML5 中弃用) |
section | style | 独立节 |
small | style | 比周围文本小一个字体大小级别的文本(在 HTML5 中弃用) |
sub | style | 下标 |
sup | style | 上标 |
strong | style | 非常重要的文本 |
table | style , width , border , align , valign | 表 |
tbody | style , align , valign | 表正文 |
td | style , width , rowspan , colspan , align , valign | 表数据单元格 |
tfoot | style , align , valign | 汇总表列的表行组 |
th | style , width , rowspan , colspan , align , valign | 表数据单元格,指定为一组单元格的标题 |
thead | style , align , valign | 指定列标题的表行组 |
tr | style , rowspan , align , valign | 表单元格行 |
tt | style | 等宽文本(在 HTML5 中弃用) |
u | style | 具有模糊注解的文本 - 默认带下划线显示 |
ul | style | 无序列表 |
有关这些元素的详细信息,请参阅 https://developer.mozilla.org/en-US/docs/Web/HTML/Element。
要使用 HTML 标记创建运行 MATLAB 代码的超链接,请参阅创建运行函数的超链接。
您可以使用 HTML 样式属性来格式化 HTML 内容。样式属性是一串 CSS 属性及其值。
支持下列 CSS 属性:
background-color
border-bottom
border-bottom-color
border-bottom-left-radius
border-bottom-right-radius
border-bottom-style
border-bottom-width
border-left
border-left-color
border-left-style
border-left-width
border-radius
border-right
border-right-color
border-right-style
border-right-width
border-spacing
border-style
border-top
border-top-color
border-top-left-radius
border-top-right-radius
border-top-style
border-top-width
border-width
color
direction
font-family
font-size
font-style
font-weight
height
hidden
line-height
margin
margin-bottom
margin-left
margin-right
margin-top
max-height
max-width
min-height
min-width
overflow
overflow-wrap
overflow-x
overflow-y
padding
padding-bottom
padding-left
padding-right
padding-top
text-align
text-anchor
text-decoration
text-indent
text-overflow
text-shadow
text-transform
title
translate
white-space
width
有关这些属性的详细信息,请参阅 https://developer.mozilla.org/en-US/docs/Web/CSS/Reference。
版本历史记录
在 R2018a 中推出R2021b: 设置文本和显示方程的样式
使用 Interpreter
名称-值参量在对话框文本中启用标记。将解释器指定为 'html'
、'latex'
、'tex'
或 'none'
。
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)