matlab空格会消失了,如何在Matlab中自动删除保存的尾随空格?

我有同样的需求,并写了一个小脚本来做一些接近的事情.将以下内容放在

MATLAB desktop shortcut中.每当您单击快捷方式按钮时,它将从编辑器中的活动文件中删除尾随空格.不如在保存时自动执行它 – 你需要记住在保存之前按下按钮 – 但差不多.测试在11b,12a和13b,但在12b也应该没问题.

希望有所帮助!

% Temp variable for shortcut. Give it an unusual name so it's unlikely to

% conflict with anything in the workspace.

shtcutwh__ = struct;

% Check that the editor is available.

if ~matlab.desktop.editor.isEditorAvailable

return

end

% Check that a document exists.

shtcutwh__.activeDoc = matlab.desktop.editor.getActive;

if isempty(shtcutwh__.activeDoc)

return

end

% Get the current text.

shtcutwh__.txt = shtcutwh__.activeDoc.Text;

% Remove trailing whitespace from each line.

shtcutwh__.lines = deblank(regexp(shtcutwh__.txt,'[^\n]*(\n)|[^\n]*$', 'match'));

% Reconcatenate lines.

shtcutwh__.addNewline = @(x)sprintf('%s\n',x);

shtcutwh__.lines = cellfun(shtcutwh__.addNewline, shtcutwh__.lines, 'UniformOutput', false);

shtcutwh__.newtxt = horzcat(shtcutwh__.lines{:});

% Set the current text.

shtcutwh__.activeDoc.Text = shtcutwh__.newtxt;

% Delete temp variable.

clear shtcutwh__

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值