次の操作を実行できます。
% 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);
前:
3210
後:
![after](https://i.stack.imgur.com/fukCg.png)
出典
2017-02-08 18:27:55
EBH
"ax.Position(1:2)= min(p);":A(:) = Bの代入でAとBの要素数が同じでなければなりません。 – Yoda
Btwなので、これで白い空白が図形で埋められます。これは私がスクリプトで定義したフィギュアの寸法に影響を及ぼしますか? – Yoda
@ Yoda、私は何のエラーもありません。上記のコードをMatlabの新鮮なセッションで実行しようとしましたか?結果として得られる 'p'の大きさはどれくらいですか? – EBH