Different result with Run (F5) and line by line debugging (F10)
Show older comments
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.
Accepted Answer
More Answers (1)
lei wang
on 23 Dec 2024
0 votes
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
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!