我有一个MATLAB首选项,我已经从首选项菜单(常规> MAT文件> MAT文件保存格式)中弄清楚了如何检查,但是想以编程方式更改它,以便可以将更改分布在startup.m文件中。我找不到
有人知道该怎么做和/或对要看的地方有建议吗?
谢谢。
为此,我相信您需要编辑matlab.prf
文件,可以通过编程方式完成...
我们要更改的行是
MatfileSaveFormat=xxxxx
其中xxxxx
可以是Sv6
,Sv7
或分别Sv7.3
与-v6,-v7和-v7.3有关。
因此,找到我们要更改的行,将文件加载到单元格数组中,找到包含文本的元素的位置,然后将该元素'MatfileSaveFormat='
替换为'MatfileSaveFormat=Sv7.3'
(或所需版本的合适行),最后用更新的版本覆盖文件。
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()
修改了以下内容以解决尚不存在的行matlab.prf
,如果首选项从未更改,则可能出现这种情况。
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);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句