0


MATLAB中uiprogressdlg函数用法

  1. uiprogressdlg函数的功能是创建进度对话框。

语法

  1. d = uiprogressdlg(fig)
  2. d = uiprogressdlg(fig,Name,Value)

说明

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

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

示例

确定进度条

  1. 创建一个名为 myprogress1.m 的程序文件,用该文件创建一个图窗和一个进度对话框。更新代码中三个不同点的 Value Message 属性。
  1. function myprogress1
  2. fig = uifigure;
  3. d = uiprogressdlg(fig,'Title','Please Wait',...
  4. 'Message','Opening the application');
  5. pause(.5)
  6. % Perform calculations
  7. % ...
  8. d.Value = .33;
  9. d.Message = 'Loading your data';
  10. pause(1)
  11. % Perform calculations
  12. % ...
  13. d.Value = .67;
  14. d.Message = 'Processing the data';
  15. pause(1)
  16. % Finish calculations
  17. % ...
  18. d.Value = 1;
  19. d.Message = 'Finishing';
  20. pause(1)
  21. % Close dialog box
  22. close(d)
  23. end
  1. 运行该程序以显示进度对话框。
  1. myprogress1

如图所示:

不确定进度条

  1. 创建一个名为 myprogress2.m 的程序文件,用该文件创建一个图窗,并在奇异值分解期间显示不确定进度条。
  1. function myprogress2
  2. fig = uifigure;
  3. d = uiprogressdlg(fig,'Title','Computing SVD',...
  4. 'Indeterminate','on');
  5. drawnow
  6. % Do the SVD computation
  7. svd(rand(5000));
  8. % close the dialog box
  9. close(d)
  10. end
  1. Indeterminate 属性设置为 'on' 将以动画方式显示进度条,指示不知道预计完成时间。计算完成后,将由 close 函数关闭对话框。
  2. 运行该程序以执行奇异值分解并显示进度对话框。
  1. myprogress2

如图所示:

带有取消按钮的确定进度条

  1. 创建一个名为 myprogress3.m 的程序文件,用该文件创建一个图窗并显示求 pi 近似值的进度条。
  1. function myprogress3
  2. fig = uifigure;
  3. d = uiprogressdlg(fig,'Title','Approximating Pi',...
  4. 'Message','1','Cancelable','on');
  5. drawnow
  6. % Approximate pi^2/8 as: 1 + 1/9 + 1/25 + 1/49 + ...
  7. pisqover8 = 1;
  8. denom = 3;
  9. valueofpi = sqrt(8 * pisqover8);
  10. steps = 20000;
  11. for step = 1:steps
  12. % Check for Cancel button press
  13. if d.CancelRequested
  14. break
  15. end
  16. % Update progress, report current estimate
  17. d.Value = step/steps;
  18. d.Message = sprintf('%12.9f',valueofpi);
  19. % Calculate next estimate
  20. pisqover8 = pisqover8 + 1 / (denom * denom);
  21. denom = denom + 2;
  22. valueofpi = sqrt(8 * pisqover8);
  23. end
  24. % Close the dialog box
  25. close(d)
  26. end
  1. Cancelable 属性设置为 'on' 将创建默认标签为取消的取消按钮。for 循环中的第一个命令检查 d.CancelRequested 的值,以查看用户是否点击了取消按钮。如果该值为 true,则程序退出循环。最后,在 for 循环结束或用户取消后,由 close(d) 命令关闭对话框。
  2. 运行该程序以求 pi 的近似值并显示进度对话框。
  1. myprogress3

如图所示:

自定义进度对话框外观

  1. 使用 HTML 指定自定义图标和格式化消息文本,以修改进度对话框的外观。
  2. 创建一个名为 myprogress4.m 的程序文件,用该文件创建一个图窗并显示进度条。将一个图像文件指定为对话框图标,然后指定对话框将其消息文本解释为 HTML。使用 winter 颜色图创建一个 RGB 颜色值矩阵。使用 for 循环来更新进度条值,并通过使用 HTML 标记来格式化和显示消息颜色。在循环完成后关闭对话框。
  1. function myprogress4
  2. fig = uifigure;
  3. d = uiprogressdlg(fig,'Icon','peppers.png', ...
  4. 'Interpreter','html');
  5. steps = 100;
  6. cmap = winter(steps)*100;
  7. for step = 1:steps
  8. r = num2str(cmap(step,1));
  9. g = num2str(cmap(step,2));
  10. b = num2str(cmap(step,3));
  11. msg = ['<p style=color:rgb(' r '%,' g '%,' b '%)> Calculating... </p>'];
  12. d.Message = msg;
  13. d.Value = step/steps;
  14. pause(0.05);
  15. end
  16. close(d)
  17. end

运行该程序以显示进度对话框。

  1. myprogress4

如图所示:

标签: matlab 开发语言

本文转载自: https://blog.csdn.net/jk_101/article/details/133358359
版权归原作者 jk_101 所有, 如有侵权,请联系我们删除。

“MATLAB中uiprogressdlg函数用法”的评论:

还没有评论