Matlab安装必备

打开.m文件总是打开新窗口

下载以下文件并解压,打开associateFiles.m并运行,打开生成的MatlabFileAssocFix.reg文件,重启MATLAB即可。

百度云链接

链接: https://pan.baidu.com/s/1LLVZeD58WtKSPTh7IbPjSw?pwd=ucdv 提取码: ucdv

修改字体

consolas字体代替matlab的默认字体,同时这个字体文件集成微软雅黑字体解决consolas无法显示中文的问题。下载链接如下,解压后右键点击.ttf文件为所有用户安装即可(全部都要装)。

百度云链接

链接: https://pan.baidu.com/s/1R2o3Y8Q2a5yAf-1D8EZYVg?pwd=m2zq 提取码: m2zq

代码美化

主要是参考以下教程:教程1教程2。将以下代码保存成formatMcode.m文件。

function formatMcode
  try %#ok
    document = matlab.desktop.editor.getActive;
    position = document.Selection;
    document.Text = format(document.Text);
    document.goToPositionInLine(position(1), position(2)) % 还原光标位置
    document.smartIndentContents();
  end
  
function code = format(code)
  code = regexprep(code, {'(\S)[ \f\v\t]+\n', '([^\n])$'}, '$1\n');
  tree = mtree(code, '-comments');
  assert(isempty(tree.mtfind('Kind', 'ERR')))
  
  % a(:) 不替换为 a( : )
  colons = tree.mtfind('Kind', 'COLON');
  colonPos = colons.position();
  colonPos = colonPos(colons.lefttreepos == colons.righttreepos);
  
  % 字符串、注释、数值中的符号以及一元操作符不处理
  exc = tree.mtfind('Kind', 'CHARVECTOR') | tree.mtfind('Kind', 'STRING') | ...
    tree.mtfind('Kind', 'DOUBLE') | tree.mtfind('Kind', 'COMMENT');
  uops = (tree.mtfind('Kind', 'UPLUS') | tree.mtfind('Kind', 'UMINUS'));
  excPos = [colonPos' ...
    cell2mat(arrayfun(@colon, exc.lefttreepos, exc.righttreepos, 'un', 0)') ...
    uops.lefttreepos'];
  
  [ops, code, start] = regexp(string(code), ...
    '\.(\^|\*|/|\\)|<=|>=|==|~=|&&|\|\||[-+*/\\^|&<>=,;:]', ...
    'match', 'split', 'start');
  idx = ~ismember(start, excPos);
  code(idx) = regexprep(code(idx), '[ \f\r\t\v]+$', '');
  code([false idx]) = regexprep(code([false idx]), '^[ \f\r\t\v]+', '');
  
  ops(idx) = ops(idx) + " ";
  idx = idx & ~ops.startsWith(["," ";"]);
  ops(idx) = " " + ops(idx);
  code = char(strjoin([code; ops ""], ''));

然后将此文件拷贝至matlab任意路径,matlab的路径可按照下面的方法查找
matlab路径查看
然后添加到收藏命令
收藏命令
此时这个命令就会出现在右上角的顶栏了
在这里插入图片描述
另外还有在谷歌搜索关键词MATLAB Code beautifier可以找到很多许多在线美化工具,如:链接1链接2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值