Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

uiprogressdlg

创建进度对话框

说明

d = uiprogressdlg(fig) 在图窗 fig 中显示确定进度对话框,并返回 ProgressDialog 对象。该图窗必须使用 uifigure 函数创建。

示例

d = uiprogressdlg(fig,Name,Value) 使用 Name,Value 参量指定 ProgressDialog 属性值。可通过属性值控制对话框的外观和行为。例如,您可以在对话框中添加标题或消息,或者指定不确定进度条。

示例

全部折叠

创建一个名为 myprogress1.m 的程序文件,用该文件创建一个图窗和一个进度对话框。更新代码中三个不同点的 ValueMessage 属性。

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

Progress dialog box with title "Please Wait" and text "Loading your data". The progress bar length is about 1/3 of the full length.

创建一个名为 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

Progress dialog box with title "Computing SVD" and an indeterminate progress bar

创建一个名为 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

Progress dialog box with title "Approximating Pi". The dialog box text is an approximation of pi, and the progress bar length is a fraction of the full length.

使用 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

Progress dialog box with an image of some peppers and a message that says "Calculating..." in blue text.

输入参数

全部折叠

目标图窗,指定为 Figure 对象。图窗必须使用 uifigure 函数创建。

名称-值参数

将可选的参量对组指定为 Name1=Value1,...,NameN=ValueN,其中 Name 是参量名称,Value 是对应的值。名称-值参量必须出现在其他参量之后,但参量对组的顺序无关紧要。

在 R2021a 之前,使用逗号分隔每个名称和值,并用引号将 Name 引起来。

示例: d = uiprogressdlg(uifigure,'Value',0.25)

注意

此处所列的属性只是一部分。有关完整列表,请参阅 ProgressDialog 属性

完成的部分,指定为 01 之间的数字。当值为 1 时,进度条达到其全长。在代码中的不同位置更改 Value,以直观指示正在运行的 App 的进度。

数据类型: double

消息,指定为字符向量、字符向量元胞数组或字符串数组。消息显示在对话框中进度条的上方。

要显示多行文本,请指定字符向量元胞数组或字符串数组。数组中的每个元素对应一行文本。每个元素中的硬分行(例如 '\n')会创建额外的文本行。

示例: d = uiprogressdlg(uifigure,'Message','Calculating result.');

标题,指定为字符向量或字符串标量。标题显示在对话框的标题栏中。

示例: d = uiprogressdlg(uifigure,'Title','Calculating');

不确定进度,指定为 'off''on',或者指定为数值或逻辑值 1 (true) 或 0 (false)。值 'on' 等效于 true'off' 等效于 false。因此,您可以使用此属性的值作为逻辑值。该值存储为 matlab.lang.OnOffSwitchState 类型的 on/off 逻辑值。

将此属性设置为 'on' 以显示动画进度条但不提供具体进度信息。此动画适用于计算时长未知的情形。

为防止不确定进度条无限期显示,请在完成计算后调用 close 函数。

允许取消,指定为 'off''on',或者指定为数值或逻辑值 1 (true) 或 0 (false)。值 'on' 等效于 true'off' 等效于 false。因此,您可以使用此属性的值作为逻辑值。该值存储为 matlab.lang.OnOffSwitchState 类型的 on/off 逻辑值。

值为 'on' 表示在对话框中显示取消按钮。您可以通过指定 CancelText 属性来自定义按钮标签。

当您允许取消时,您必须检查 CancelRequested 属性的值,并在值为 true 时调用 close 函数。否则,对话框将无限期显示。

对话框文本解释器,指定为:

  • '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{specifier}字体名称 - 将 specifier 替换为字体系列的名称。您可以将此说明符与其他修饰符结合使用。'\fontname{Courier} text'
\fontsize{specifier}字体大小 - 将 specifier 替换为以磅为单位的数值标量值。'\fontsize{15} text'
\color{specifier}字体颜色 - 将 specifier 替换为以下颜色之一:redgreenyellowmagentablueblackwhitegraydarkGreenorangelightBlue'\color{magenta} text'
\color[rgb]{specifier}自定义字体颜色 - 将 specifier 替换为三元素 RGB 三元组。'\color[rgb]{0,0.5,0.5} text'

下表列出了 'tex' 解释器所支持的特殊字符。

字符序列符号字符序列符号字符序列符号

\alpha

α

\upsilon

υ

\sim

~

\angle

\phi

ϕ

\leq

\ast

*

\chi

χ

\infty

\beta

β

\psi

ψ

\clubsuit

\gamma

γ

\omega

ω

\diamondsuit

\delta

δ

\Gamma

Γ

\heartsuit

\epsilon

ϵ

\Delta

Δ

\spadesuit

\zeta

ζ

\Theta

Θ

\leftrightarrow

\eta

η

\Lambda

Λ

\leftarrow

\theta

θ

\Xi

Ξ

\Leftarrow

\vartheta

ϑ

\Pi

Π

\uparrow

\iota

ι

\Sigma

Σ

\rightarrow

\kappa

κ

\Upsilon

ϒ

\Rightarrow

\lambda

λ

\Phi

Φ

\downarrow

\mu

µ

\Psi

Ψ

\circ

º

\nu

ν

\Omega

Ω

\pm

±

\xi

ξ

\forall

\geq

\pi

π

\exists

\propto

\rho

ρ

\ni

\partial

\sigma

σ

\cong

\bullet

\varsigma

ς

\approx

\div

÷

\tau

τ

\Re

\neq

\equiv

\oplus

\aleph

\Im

\cup

\wp

\otimes

\subseteq

\oslash

\cap

\in

\supseteq

\supset

\lceil

\subset

\int

\cdot

·

\o

ο

\rfloor

\neg

¬

\nabla

\lfloor

\times

x

\ldots

...

\perp

\surd

\prime

´

\wedge

\varpi

ϖ

\0

\rceil

\rangle

\mid

|

\vee

\langle

\copyright

©

LaTeX 标记

使用 LaTeX 标记来格式化和显示数学表达式、方程和特殊字符。使用美元符号将标记的文本括起来。例如,对于行内模式,使用 '$\int_1^{20} x^2 dx$',对于显示模式,使用 '$$\int_1^{20} x^2 dx$$'

显示的文本将使用默认的 LaTeX 字体样式。您可以使用 LaTeX 标记来更改字体样式。

MATLAB® 支持大多数标准 LaTeX 数学模式命令。有关详细信息,请参阅支持的 LaTeX 命令

HTML 标记

使用 HTML 标记显示链接和自定义字体样式。

解释器支持部分 HTML 标记。一般情况下,解释器支持与文本相关的标记和样式。不支持的标记和样式将被忽略。

下表列出了支持的元素和元素属性。

HTML 元素属性描述
astyle, target, href, title超链接
abbrstyle, title缩写
addressstyle联系信息
articlestyle自包含的独立内容
asidestyle与主要内容间接相关的内容
bstyle粗体文本
bdistyle, dir格式与周围文本方向不同的内容
bdostyle, dir格式与周围文本方向不同的内容
bigstyle比周围文本大一个字体大小级别的文本(在 HTML5 中已弃用)
blockquotestyle, cite扩展引用
br不适用换行符
captionstyle表标题
centerstyle水平居中的内容
citestyle创造性工作的标题
codestyle代码片段
colstyle, align, valign, span, width表中的列
colgroupstyle, align, valign, span, width表中的一组列
ddstyle描述列表中的项或值
delstyle, datetime从文档中删除的文本
detailsstyle, open文本仅在切换到 'open' 状态时才可见的交互式小组件
dlstyle描述列表
dtstyle描述列表中的项或值
emstyle强调的文本(通常以粗体显示)
fontstyle, color, size, face具有指定字体属性的文本(在 HTML5 中弃用)
footerstyle页脚
h1. h2, h3, h4, h5, h6style节标题 - <h1> 是最高级别的标题,<h6> 是最低级别的标题
headerstyle介绍性内容
hrstyle主题换行
istyle偏离周围内容的文本 - 默认以粗体方式呈现
insstyle, datetime插入文档中的文本
listyle列表中的项
markstyle标记或突出显示的文本
olstyle有序列表
pstyle段落
prestyle预设格式的文本
sstyle带删除线的文本
strikestyle带删除线的文本(在 HTML5 中弃用)
sectionstyle独立节
smallstyle比周围文本小一个字体大小级别的文本(在 HTML5 中弃用)
substyle下标
supstyle上标
strongstyle非常重要的文本
tablestyle, width, border, align, valign
tbodystyle, align, valign表正文
tdstyle, width, rowspan, colspan, align, valign表数据单元格
tfootstyle, align, valign汇总表列的表行组
thstyle, width, rowspan, colspan, align, valign表数据单元格,指定为一组单元格的标题
theadstyle, align, valign指定列标题的表行组
trstyle, rowspan, align, valign表单元格行
ttstyle等宽文本(在 HTML5 中弃用)
ustyle具有模糊注解的文本 - 默认带下划线显示
ulstyle无序列表

有关这些元素的详细信息,请参阅 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 中推出

全部展开

另请参阅

函数

属性