Different result with Run (F5) and line by line debugging (F10)

1 回表示 (過去 30 日間)
Joshua
Joshua 2021 年 12 月 2 日
回答済み: lei wang 2024 年 12 月 23 日
Considering the following minimum working example:
figure()
ax1 = subplot(2,1,1); hold on;
plot([0 1],[0 0],'DisplayName','Line 1')
plot([0 1],[1 1],'DisplayName','Line 2')
plot([0 1],[2 2],'DisplayName','Line 3')
plot([0 1],[3 3],'DisplayName','Line 4')
legend('show','Location','Northoutside')
ax1Pos = ax1.Position
ax2 = subplot(2,1,2); hold on;
plot([0 1],[0 0],'DisplayName','Line 1')
plot([0 1],[1 1],'DisplayName','Line 2')
plot([0 1],[2 2],'DisplayName','Line 3')
plot([0 1],[3 3],'DisplayName','Line 4')
I observe a difference in the value of ax1Pos depending on wether I run the script (F5) or step through line by line (F10). For the first case I get the position of the subplot axis INCLUDING the legend, in the second case I get the position of the subplot axis EXCLUDING the legend. Any ideas why that is the case?
Output:
>> test
ax1Pos =
0.130000000000000 0.583837209302326 0.775000000000000 0.341162790697675
>> test
8 ax1Pos = ax1.Position
ax1Pos =
0.130000000000000 0.583837209302326 0.775000000000000 0.155930332361357
I am using MATLAB R2021b.

採用された回答

Voss
Voss 2021 年 12 月 2 日
Someone more knowledgeable than me may know for sure, but it may be because the event queue gets processed each time you dbstep, whereas the event queue doesn't get processed until the end when you just run the code. If you put a drawnow() immediately before the line "ax1Pos = ax1.Position", I believe you should see the same position in both cases (at least this is what I observe in R2017b).
  1 件のコメント
Joshua
Joshua 2021 年 12 月 2 日
Worked like a charm, thanks!

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

その他の回答 (1 件)

lei wang
lei wang 2024 年 12 月 23 日
when you using complex object oriented programing, it may occur for the synchronization issue.
sometimes it is caused for the debuger will call different functions with the same names

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by