timer causes drawing problem when loading a figure

1 回表示 (過去 30 日間)
Jim Hokanson
Jim Hokanson 2017 年 9 月 21 日
編集済み: Jan 2017 年 9 月 22 日
When running a GUI that has a timer callback, I notice that loading other GUI figures often fails (incorrect rendering). Is this known behavior? Are there any workarounds? I assume that the code loading the figures isn't immune to a timer spontaneously injecting code ... (e.g. updating the current figure or axes).
Edit: I'm using Matlab 2016a or newer (need to check specific version) on Windows 7. The code to load the figure is:
fig = openfig(fig_path);
After running this line the figure is rendered incorrectly. The figure is the wrong size and components are not where they are supposed to be.
The loaded figures have been created by GUIDE with no code generation (just figure layout). The remaining code (not shown) only adds callbacks and updates display strings; no components are created or positions/sizes changed.
  3 件のコメント
Jim Hokanson
Jim Hokanson 2017 年 9 月 22 日
I've updated the question. I don't currently have access to the machines on which I can run this code. When I do I can add the specific versions as well as pictures.
Jan
Jan 2017 年 9 月 22 日
編集済み: Jan 2017 年 9 月 22 日
@Jim: Please post a screenshot of the correct and the garbled figure. What is the contents of the timer callback? Does it change the current figure, object or directory?

サインインしてコメントする。

回答 (1 件)

Jan
Jan 2017 年 9 月 22 日
A timer callback can change the current figure and current axes. How do you "load" the figures? Do the conflict appear inside the OpeningFcn? Which objects are concerned? Does any user-defined code run, which assume the current figure and axes to be static? Then a solution would be to define the 'Parent' property in every case:
FigH = figure;
AxesH = axes('Parent', 'FigH);
plot(1:10, rand(1, 10), 'Parent', AxesH);
Then a timer callback cannot disturb the creation.
Another idea would be not to change the current figure and axes inside timer callbacks.
  1 件のコメント
Jim Hokanson
Jim Hokanson 2017 年 9 月 22 日
Hi Jan,
Thanks for the answer. I've updated the question to clarify the use case. The problem is with the load figure call, not with secondary component creation after the figure has been loaded.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by