Why would MATLAB preferences unexpectedly reset to default?
Show older comments
Many thanks in advance for your help and advice.
At least a dozen times now, it seems that the changes I have made to MATLAB's preferences and settings have reset to the default. To be clear, there's only really one setting I'm bothering with: whether the command line is set to loose or compact (I prefer compact, but loose is default). As such, I don't really know if it's just that setting or if it's everything, but regardless, it's troublesome.
I don't really know where to start looking to diagnose it myself, and the closest issue I've found online only explained how to find the preferences file. Since this has happened to me so often and it's rather annoying to reset it each time, I'd like to figure out why it's happening and how to prevent it.
Please let me know if any further information or logfiles are needed.
Answers (1)
Simar
on 18 Oct 2023
0 votes
Hi Ian M,
I understand that you are facing difficulty in saving preferences as it keeps on resetting to default. MATLAB preferences are stored in a file named ‘matlab.prf’. This file is in MATLAB preferences directory, which varies depending on operating system. Here is a way to locate it:
- Open MATLAB
- Type ‘prefdir’ in the MATLAB command window and press Enter. This will display the location of MATLAB preferences directory.
This might be due to MATLAB not being able to properly save changes to the ‘matlab.prf’ file. It can occur due to several reasons such as lack of writing permissions, disk space, or unexpected MATLAB termination. Here are some steps to troubleshoot:
- Make sure to have write permissions for the directory containing the ‘matlab.prf’ file. On Windows, right-click the ‘matlab.prf’ file, select Properties, then Security. Check that the user account has written permissions.
- Ensure that there is enough disk space to save changes to the ‘matlab.prf’ file.
- Check if MATLAB closes properly. If MATLAB terminates unexpectedly (e.g., system crash, forced termination), it might not have a chance to save changes to the matlab.prf file.
- As a workaround, manually backup the ‘matlab.prf’ file. After setting the preferences, close MATLAB, navigate to MATLAB preferences directory, and create a copy of the ‘matlab.prf’ file. If the preferences are reset, restore them by replacing the ‘matlab.prf’ file with the backup.
The preference related to the command line you are referring controls the format of the output displayed in the MATLAB Command Window. The 'loose format’ includes blank lines to separate output lines, while the 'compact format’ does not. I understand currently the preferred option is the ‘compact’, but it keeps reverting to the default ‘loose’ option. The following steps can be used to troubleshoot and potentially fix the issue:
- Use the ‘format’ function in MATLAB scripts to programmatically set the output format to 'compact'. Simply add ‘format compact’ at the beginning of the scripts.
- Create a startup script that sets the output format to 'compact' every time MATLAB starts. Open MATLAB and type ‘userpath’ in the Command Window. MATLAB will return the path to the user directory. This is the directory where MATLAB will look for a ‘startup.m’ file each time it starts. Create a new script in the MATLAB startup directory, add the line ‘format compact’, and save the script as ‘startup.m’. Now, every time on starting MATLAB, it will run this ‘startup.m’ script and set the output format to 'compact'.
Please note that if a ‘startup.m’ file already exists in the startup directory, one should open it and add ‘format compact’ to it, rather than creating a new 'startup.m' file.
Kindly refer to the documentation links below for further information:
- prefdir: https://in.mathworks.com/help/releases/R2023b/matlab/ref/prefdir.html?s_tid=doc_ta
- format: https://in.mathworks.com/help/releases/R2023b/matlab/ref/format.html#mw_5f3d66eb-5e13-4517-8573-e60f3f48169c
- userpath: https://in.mathworks.com/help/releases/R2023b/matlab/ref/userpath.html?searchHighlight=userpath&s_tid=doc_srchtitle
- startup: https://in.mathworks.com/help/releases/R2023b/matlab/ref/startup.html?searchHighlight=startup&s_tid=doc_srchtitle
Hope it helps!
Best Regards
Simar
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!