How to Install Clang specifically While trying to run a MATLAB script, I am getting the following error:

Compiling minFunc files...
Building with 'Xcode with Clang'.
Error using mex
xcrun: error: invalid active developer path (/Applications/Xcode.app/Contents/Developer), missing
xcrun at: /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun


On searching further, I got the following solution to install command-line-tools using the command:

xcode-select --install

but it is giving me:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates


On running brew config I got the following information:

HOMEBREW_VERSION: &gt;=1.7.1 (shallow or no git repository)
ORIGIN: (none)
HEAD: (none)
Last commit: never
Core tap ORIGIN: (none)
Core tap HEAD: (none)
Core tap last commit: never
HOMEBREW_PREFIX: /usr/local
HOMEBREW_LOGS: /Users/swastik/Library/Logs/Homebrew
HOMEBREW_NO_ANALYTICS_THIS_RUN: 1
CPU: octa-core 64-bit haswell
Homebrew Ruby: 2.3.7 =&gt; /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
Clang: xcrun: error: invalid active developer path (/Applications/Xcode.app/Contents/Developer), missing xcrun at: /Applications/Xcode.app/Contents/Developer/usr/bin/xcrun
N/A
Git: N/A
Curl: 7.54.0 =&gt; /usr/bin/curl
macOS: 10.13.6-x86_64
CLT: 10.1.0.0.1.1539992718
Xcode: dunno


How to solve this problem?
Do a software update.

Go to  Apple menu → System Preferences... → Software Update (on macOS Mojave) or Apple menu → App Store... → Updates (on earlier). Be sure to update Xcode. Then go back to Terminal and run

xcode-select --install