Matlab 2014b 多图居中标题 subtitle

2014b内核有变化,之前的版本不能用,改成自适应的,兼容2014b及之前版本

Matlab 2014b 多图居中标题 subtitle - 葱油肉包 - 葱油肉包

function ht = subtitle(text)
% SUBTITLE ht = subtitle(text)
% Input:
%     text  Title of the graph
% Output:
%     ht   Handle of this text
%
% Example:
%   for kk = 1:6
%       subplot(2,3,kk);
%       plot(magic(3));
%   end
%   ht = subtitle('Title in the Middle Top');
%   See also SET, POSITION, SUBPLOT, SUBTIGHT
%
 
% by Curb
% Last edit 2014-11-7
% automatically adapted to matlab 2014b
% Latest revised 2013-5-10
% change algorithm to adapted to traditional subplot
% and specified positions
% Last revised 2011-04-15

    h1 = get(gcf,'children');

    ver = version;
    ver1 = str2double(ver(1:3));
    if ver1>=8.4
        nf = numel(h1);
        for kf = 1:nf
            pos(kf,:) = get(h1(kf),'position');
        end
    else
        ind1 = strcmp('on',get(h1,'visible'));
        ind2 = strcmp('on',get(h1,'handlevisibility'));
        ind = find((ind1+ind2)==2);
        for kd = 1:numel(ind)
            pos(kd,:) = get(h1(ind(kd)),'position');
        end
    end

    left = min(squeeze(pos(:,1)));
    top = max(squeeze(pos(:,2)+pos(:,4)));
    % bottom = min(squeeze(pos(:,2)));
    right = max(squeeze(pos(:,1)+pos(:,3)));
    axest = [left,top-0.01,right-left,0.01];
    ht = axes('Position',axest);
    axis(ht,'off')
    title(ht,text)

end

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值