问题
Is there an automated way of retrieving the tab size of the matlab editor and command window? Yes, you can just open the preferences window and look it up yourself, but I want it automated. Actually I think this could be generalized to retrieving any of those user preferences in the screenshot below.

回答1:
I found the solution pretty quickly and after digging in thought it's best to share this link:
http://undocumentedmatlab.com/blog/changing-system-preferences-programmatically/
So what you do is:
Open up the preferences file and look for the preference you want to read:
edit(fullfile(prefdir,'matlab.prf'));
In my case it were the lines
CommandWindowSpacesPerTab=I4
andEditorSpacesPerTab=I4
that looked promising. I think the I stands for the type (integer).Test it out by loading the value:
com.mathworks.services.Prefs.get<type>Pref(<pref-name>)
In my case:
>> com.mathworks.services.Prefs.getIntegerPref('EditorSpacesPerTab') ans = 4
There is also a small overlap with this question: Saving settings in matlab
EDIT: Apparently, when using this function, it doesn't read the default value of the preference. ie: when you haven't yet changed the value of the preference, the value isn't saved into the preference file, and thus can't be loaded this way. The functions just returns 0. For now, I'm detecting this case manually:
if loadedpref==0
set default
end
EDIT2: I also use matlab in linux commandline, which has it's own tab setting (usually defaulted to 8). To detect this situation I used the following:
function retval = isCommandWindowOpen()
jDesktop = com.mathworks.mde.desk.MLDesktop.getInstance;
retval = ~isempty(jDesktop.getClient('Command Window'));
end
来源:https://stackoverflow.com/questions/10817832/get-tab-size-through-command-line