Different result with Run (F5) and line by line debugging (F10)
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Voss
el 2 de Dic. de 2021
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).
Más respuestas (0)
Ver también
Categorías
Más información sobre Subplots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!