Height of a figure spontaneously changes.
조회 수: 2 (최근 30일)
이전 댓글 표시
When I run the following code, I find that the OuterPosition properties of both figures report the same height and width, as expected.
close all ; for i=1:2; figure(i);plot(rand(1,5)); end;
H=flip( findobj('Type','figure') );
dpos =[0,0;
1,0];
dpos=dpos.*H(1).OuterPosition(3:4).*[1.01,1.0];
OP=H(1).OuterPosition;
for i=1:2
H(i).OuterPosition=OP;
H(i).OuterPosition(1:2)=OP(1:2)+dpos(i,:);
end
OuterPositions=vertcat(H.OuterPosition)
OuterPositions =
26.0000 542.0000 576.0000 459.0000
607.7600 542.0000 576.0000 459.0000
On the screen, however, the figure windows are of different sizes. Why does the height of the first figure grow spontaneously?
댓글 수: 1
채택된 답변
DGM
2022년 1월 17일
It's seems like the figure properties aren't updated immediately. You're reading the properties before they're ready and then the math you perform on them ends up making one window larger. I don't know what causes this delay.
close all ;
for i=1:2; figure(i);plot(rand(1,5)); end;
H=flip( findobj('Type','figure') );
dpos = [0,0;
1,0];
H(1).OuterPosition
pause(1)
H(1).OuterPosition
dpos=dpos.*H(1).OuterPosition(3:4).*[1.01,1.0];
OP=H(1).OuterPosition;
for i=1:2
H(i).OuterPosition=OP;
H(i).OuterPosition(1:2)=OP(1:2)+dpos(i,:);
end
OuterPositions=vertcat(H.OuterPosition)
ans =
679 554 562 447
ans =
679 554 562 502
OuterPositions =
1.0e+03 *
0.6790 0.5540 0.5620 0.5020
1.2466 0.5540 0.5620 0.5020
댓글 수: 2
DGM
2022년 1월 18일
편집: DGM
2022년 1월 18일
I imagine there's something in the background that's depending on reading those transient properties that you're modifying. It's probably just a matter of timing that one gets influenced and the other doesn't.
This line
H(i).OuterPosition = OP;
sets offset as well as height,width. At this point, the height and width stored in OP are the transient (undersize) values. Sometime between setting this property for the first and second figures, something gets updated in the background, and those yet unrealized changes are immediately overwritten when setting the property on the second figure. So figure 1 undergoes the magical resizing, but figure 2 is forced to stay at the undersized temporary geometry.
I don't get it either, but I've grown accustomed to dealing with laggy window managers and stale properties in my ad-hoc bash automation scripts, so that's my bumbling interpretation based on little more than a similarity in the character of the frustration involved. I'm probably at least half wrong.
IA's suggestion of drawnow() is something that rarely crosses my mind, but is probably way smarter than a fixed delay. That's just my bash habits showing.
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Performance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!