다음을 수행 할 수 있습니다 :
% creat some 3D plot:
x = 1:0.1:10;
y = x;
[X,Y] = meshgrid(x,y);
f = @(x,y) sin(x).*cos(y);
Z = f(X,Y);
surf(X,Y,Z)
xlabel('Xsomething')
ylabel('Ysomething')
zlabel('Zsomething')
%%% here it starts: %%%
ax = gca;
post = findall(ax,'Type','Text'); % get all text handles
p = zeros(numel(post),2);
% collect all the position vectors:
for k = 1:numel(post)
post(k).Units = 'normalized'; % set units to the normelized figure units
% the 'position' of the text is relative to the axes, so we convert it
% to the figure units:
p(k,:) = post(k).Position(1:2)+ax.Position(1:2);
end
% find the most left and bottom items,
% and move them to the borders of the figure:
ax.Position(1:2) = min(p);
% fill the rest of the figure with th axes:
ax.Position(3:4) = 1-ax.Position(1:2);
전 :
후 :
출처
2017-02-08 18:27:55
EBH
"ax.Position (1 : 2) = min (p);"에 대한 오류가 있습니다. 할당 A (:) = B에서 A와 B의 요소 수는 동일해야합니다. – Yoda
Btw, 그래서 이것으로 공백이 그림으로 채워집니다. 이것이 제가 스크립트에서 정의한 Figure의 크기에 영향을 줍니까? – Yoda
@ 요다, 나는 어떤 에러도 내지 않는다. 위의 코드를 Matlab의 새로운 세션에서 실행하려고 했는가? 어떤 크기의 결과'p'입니까? – EBH