如何从代码而不是从菜单更改MATLAB首选项? [英] How do I change MATLAB preferences from code, not from menu?

查看:261
本文介绍了如何从代码而不是从菜单更改MATLAB首选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个MATLAB首选项,我已经从首选项菜单(常规> MAT文件> MAT文件保存格式)中弄清楚了如何检查,但是想以编程方式更改它,以便我可以在启动时分发更改.m文件.我找不到.

I have a MATLAB preference that I have figured out how to check from the preferences menu (General > MAT-Files > MAT-file save format), but want to change it programmatically so that I can distribute the change in the startup.m file. I can't find it.

有人知道该怎么做和/或对哪里看有建议吗?

Does someone know how to do this and/or have a suggestion of where to look?

谢谢.

推荐答案

为此,我相信您需要编辑matlab.prf文件,该文件可以通过编程方式完成...

To do this I believe you would need to edit the matlab.prf file, which can be done programatically...

我们要更改的行是

MatfileSaveFormat=xxxxx

其中xxxxx可以分别是与-v6,-v7和-v7.3有关的Sv6Sv7Sv7.3.

where xxxxx can either be Sv6, Sv7 or Sv7.3 relating to -v6, -v7 and -v7.3 respectively.

因此找到我们要更改的行,将文件加载到单元格数组中,找到包含文本'MatfileSaveFormat='的元素的位置,然后将该元素替换为'MatfileSaveFormat=Sv7.3'(或所需版本的合适行) ,最后用更新的版本覆盖文件.

so to find the line we want to change, load file into a cell array, find the location of the element containing the text 'MatfileSaveFormat=' and replace that element with 'MatfileSaveFormat=Sv7.3' (or the suitable line for the required version), finally overwrite the file with the updated version.

pref = regexp( fileread(fullfile(prefdir,'matlab.prf')), '\n', 'split');
pref{find(~cellfun(@isempty,regexp(pref,'MatfileSaveFormat=')))}=...
    'MatfileSaveFormat=Sv7.3';

fid = fopen(fullfile(prefdir,'matlab.prf'), 'w');
fprintf(fid, '%s\n', A{:});
fclose(fid);

注意:在2013a中,这不会在查看时更新设置,但会影响save()

note: in 2013a this does not update the settings when viewed, but does effect the file type coming out of save()

对以下内容进行了修改,以解决matlab.prf中尚不存在的行,如果首选项从未更改,就会出现这种情况.

The Following is modified to account for line not yet existing in matlab.prf , which it appears is the case if the preference has never been changed.

pref = regexp( fileread(fullfile(prefdir,'matlab.prf')), '\n', 'split');
loc = find(~cellfun(@isempty,regexp(pref,'MatfileSaveFormat=')));

if isempty(loc); pref{end+1} = 'MatfileSaveFormat=Sv7.3';
else;            pref{loc} = 'MatfileSaveFormat=Sv7.3';
end

fid = fopen(fullfile(prefdir,'matlab.prf'), 'w');
fprintf(fid, '%s\n', A{:});
fclose(fid);

这篇关于如何从代码而不是从菜单更改MATLAB首选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆