matlab撤销网格线mess,去掉MatlabFigure pdf输出周围的空白

我最喜欢@Antonio的方法,但它仍然留有太多的空白,我正在寻找一个单一的绘图解决方案,导出到vector pdf中,以便在LaTeX中使用。

注意,与安东尼奥的脚本不同,这只适用于没有子情节的人物。

function SaveFigureAsVectorPDF(InputFigureHandle, OutFileName, ShouldPrintAxes)

%% Check input parameters

[NumberOfFigures, ~] = size(InputFigureHandle);

if(NumberOfFigures ~= 1)

error('This function only supports one figure handle.');

end

if(isempty(OutFileName))

error('No file path provided to save the figure to.');

end

cUnit = 'centimeters';

%% Copy the input figure so we can mess with it

%Make a copy of the figure so we don't modify the properties of the

%original.

FigureHandleCopy = copy(InputFigureHandle);

%NOTE: Do not set this figure to be invisible, for some bizarre reason

% it must be visible otherwise Matlab will just ignore attempts

% to set its properties.

%

% I would prefer it if the figure did not briefly flicker into

% view but I am not sure how to prevent that.

%% Find the axis handle

ChildAxisHandles = get(FigureHandleCopy, 'Children');

NumberOfChildFigures = length(ChildAxisHandles);

if(NumberOfChildFigures ~= 1)

%note that every plot has at least one child figure

error('This function currently only supports plots with one child figure.');

end

AxisHandle = ChildAxisHandles(1);

%% Set Units

% It doesn't matter what unit you choose as long as it's the same for

% the figure, axis, and paper. Note that 'PaperUnits' unfortunately

% does not support 'pixels' units.

set(FigureHandleCopy, 'PaperUnits', cUnit);

set(FigureHandleCopy, 'Unit', cUnit);

set(AxisHandle, 'Unit', cUnit);

%% Get old axis position and inset offsets

%Note that the axes and title are contained in the inset

OldAxisPosition = get(AxisHandle, 'Position');

OldAxisInset = get(AxisHandle, 'TightInset');

OldAxisWidth = OldAxisPosition(3);

OldAxisHeight = OldAxisPosition(4);

OldAxisInsetLeft = OldAxisInset(1);

OldAxisInsetBottom = OldAxisInset(2);

OldAxisInsetRight = OldAxisInset(3);

OldAxisInsetTop = OldAxisInset(4);

%% Set positions and size of the figure and the Axis

if(~ShouldPrintAxes)

FigurePosition = [0.0, 0.0, OldAxisWidth, OldAxisHeight];

PaperSize = [OldAxisWidth, OldAxisHeight];

AxisPosition = FigurePosition;

else

WidthWithInset = OldAxisWidth + OldAxisInsetLeft + OldAxisInsetRight;

HeightWithInset = OldAxisHeight + OldAxisInsetTop + OldAxisInsetBottom;

FigurePosition = [0.0, 0.0, WidthWithInset, HeightWithInset];

PaperSize = [WidthWithInset, HeightWithInset];

AxisPosition = [OldAxisInsetLeft, OldAxisInsetBottom, OldAxisWidth, OldAxisHeight];

end

set(FigureHandleCopy, 'Position', FigurePosition);

set(AxisHandle, 'Position', AxisPosition);

%Note: these properties do not effect the preview but they are

% absolutely necessary for the pdf!!

set(FigureHandleCopy, 'PaperSize', PaperSize);

set(FigureHandleCopy, 'PaperPosition', FigurePosition);

%% Write the figure to the PDF file

print('-dpdf', OutFileName);

set(FigureHandleCopy, 'name', 'PDF Figure Preview', 'numbertitle', 'off');

%If you want to see the figure (e.g., for debugging purposes), comment

%the line below out.

close(FigureHandleCopy);

end

示例图像:

rjif0.png

无轴:

ZTDMk.png

测试代码:

%% Generates a graph and saves it to pdf

FigureHandle = figure;

plot(1:100);

title('testing');

%with axes

SaveFigureAsVectorPDF(FigureHandle, 'withaxes.pdf', true);

%without axes

SaveFigureAsVectorPDF(FigureHandle, 'withoutaxes.pdf', false);

DES是一种对称加密算法,全称为数据加密标准(Data Encryption Standard)。它使用相同的密钥进行加密和解密,密钥长度为64位,明文长度为64位。DES算法由一系列的轮函数和密钥调度算法组成,通过多轮迭代运算来实现加密和解密操作。 在提供的代码中,可以看到三个函数:convert_bin2mess、convert_mess2bin和主函数。其中,convert_bin2mess函数将二进制字符串转换为明文字符串,convert_mess2bin函数将明文字符串转换为二进制字符串,主函数则使用DES算法进行加密和解密操作。 在主函数中,首先定义了一个密码(keyword)和明文(text),然后调用convert_mess2bin函数将明文转换为二进制字符串。接着,使用generate_keys函数生成加密密钥。然后,调用DES函数对二进制字符串进行加密操作,将结果存储在bin_result中,并调用convert_bin2mess函数将密文转换为明文字符串,存储在result中。之后,调用flipud函数将加密密钥倒序,得到解密密钥,再次调用DES函数对密文进行解密操作,将结果存储在bin_de_result中,并调用convert_bin2mess函数将解密后的密文转换为明文字符串,存储在de_result中。最后,通过比较明文和解密后的密文来判断加密和解密是否成功。 DES算法是一种经典的加密算法,具有较高的安全性和广泛的应用场景。它在网络通信、数据存储、安全传输等领域都有重要的作用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值