【问题标题】:Waitbar in horizontal steps, matlab水平步骤中的Waitbar,matlab
【发布时间】:2011-05-25 15:05:35
【问题描述】:

我正在尝试修改此代码

h = waitbar(0,'Please wait...');

for i=1:10, % computation here %  waitbar(i/10) end
close(h)

如何将等待栏分为 10 个步骤。我的意思是它应该看起来像

-------------------
| | | | | | | | | |
-------------------

【问题讨论】:

    标签: matlab


    【解决方案1】:

    以下代码将允许您在waitbar 中添加垂直线:

    hWait = waitbar(0,'Progress');  %# Create the waitbar and return its handle
    hAxes = get(hWait,'Children');  %# Get the axes object of the waitbar figure
    xLimit = get(hAxes,'XLim');     %# Get the x-axis limits
    yLimit = get(hAxes,'YLim');     %# Get the y-axis limits
    xData = repmat(linspace(xLimit(1),xLimit(2),11),2,1);  %# X data for lines
    yData = repmat(yLimit(:),1,11);                        %# Y data for lines
    hLine = line(xData,yData,'Parent',hAxes,...  %# Plot the lines on the axes...
                 'Color','k',...                 %#   ... in black...
                 'HandleVisibility','off');      %#   ... and hide the handles
    

    运行上面的代码,然后做waitbar(0.35,hWait);,你会看到这样的图:

    注意:图中的黑线(我添加的垂直线进度条周围已经存在的框)将间歇性地出现在红色的上方或下方更新时的进度条。这似乎是 WAITBAR 行为方式的现有错误,我还没有找到解决方法来纠正它。但是,在MathWorks File Exchange 上可以找到很多替代品,所以如果内置功能不适合你,我肯定会检查一下。 ;)

    【讨论】:

    • 谢谢,它工作正常。你还清除了另一点。应该有明确的解决方案。
    【解决方案2】:

    您可以随时从零开始并更新消息。例如:

    h = waitbar(0, 'Please wait...');
    for step=1:10
        waitbar(0, h, ['Step ' num2str(step) '/10 - Please wait...']);
        for i=1:100
            % Work...
            waitbar(i/100, h);
        end
    end
    

    【讨论】:

      【解决方案3】:

      我不确定如何将步骤添加到等待栏本身,但您可以添加一条动态消息,该消息会发生变化以显示完成了多少计算:

      h = waitbar(0,'Please wait...0% complete');
      for i = 1:10
          % Computation here
          waitbar(i/10, h, sprintf('Please wait...%d%% complete',100*(i/10)));
      end
      close(h);
      

      【讨论】:

        【解决方案4】:

        由于waitbar 是一个灵活性较低的内置函数,我认为没有简单的方法可以让等待栏看起来像你想要的那样。如果真的很重要,您可以在几种进度模式下绘制等待栏并将其保存为图片。然后你可以在一个看起来像等待栏的简单 gui 中加载图片! ;)

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2012-05-02
          • 1970-01-01
          • 2014-09-12
          • 1970-01-01
          相关资源
          最近更新 更多