MATLAB: Does MATLAB fail to start on macOS citing with a permissions directory warning when launched from the terminal

MATLAB

When I try to launch MATLAB on my Mac, it bounces once or twice in the dock and I see the splash screen for a second, but then MATLAB never loads. If I launch from the Terminal by running $MATLAB/bin/matlab I see an error like this one in the Terminal window:
 
"Check Directory Permissions.Warning: failed to create preference directory /Users/<user>/.matlab/R2016a."
What does this mean and how can I fix it?

Best Answer

This error indicates that the user you are launching MATLAB as does not have permission to write to the MATLAB preferences directory. Usually this is due to a problem which can sometimes occur when using Migration Assistant to transfer data from one Mac to another.
To resolve the issue, change the owner on the MATLAB preferences directory to match the logged in user. First, run this command to determine who the logged in user is:
whoami
Then, run this command to change ownership on the MATLAB preferences directory. Replace <username> with the results from the previous command:
R2016a and earlier
sudo chown -R <username> /Users/<username>/.matlab
R2016b and later
sudo chown -R <username> /Users/<username>/Library/Application\ Support/MathWorks
You need to be an administrator to run this command and you will be prompted for your password before running it. Once you have changed the owner of your MATLAB preferences directory to you, you should be able to run MATLAB.