1

我使用以下命令在matlab中添加了一个等待栏,但它想要进行修改。

h = waitbar(0,'Algorithm is running Xth simulation');
N = 30;
 for i = 1:N
   ...

 waitbar(i / N)
end;
close(h) 

现在,我想更改等待栏,以便在每个循环中显示“算法正在模拟运行”

4

1 回答 1

1

根据The Fine Manual of waitbar,您可以将带有更新消息的字符串传递给它。格式化要插入一些数字的字符串最容易使用sprintf. 例子:

n = 10;
h = waitbar(0, sprintf('Starting %i simulations', n));
for i=1:n
    pause(1); % pretend to do some work, your simulation code goes here
    waitbar(i / n, h, sprintf('Finished the %ith simulation', i))
end
pause(1) % wait a little bit before closing it.
close(h)
于 2013-10-16T23:06:48.367 回答