File Exchange

image thumbnail


version 1.1 (4.25 KB) by Jorg Woehl
Name and version number of the operating system


Updated 22 Apr 2021

From GitHub

View Version History

View license on GitHub

OS = detectOS

returns the name of the operating system as a lowercase character vector, such as 'windows', 'macos' (which includes OS X), 'solaris', 'aix', 'ubuntu', 'centos', and many other Unix/Linux distributions. It is thus much more fine-grained than MATLAB's built-in ispc / ismac / isunix and computer functions. If the OS cannot be determined, an error is thrown.

[OS, OSVersion] = detectOS

also returns the OS version number as a numeric row vector. For example, Windows 7 SP1 (version 6.1.7601) is reported as OS = 'windows' and OSVersion = [6, 1, 7601]. If the OS version cannot be determined, a warning is issued and the empty numeric array is returned.

detectOS was tested with various MATLAB releases on Windows 10, Windows 8.1 Update 1, Windows 7, Windows XP Pro SP3, macOS Big Sur, macOS Catalina, macOS Sierra, OS X El Capitan, Ubuntu 16.04 LTS, Ubuntu 15.10, Ubuntu 14.04 LTS, CentOS 7, and CentOS 6.8 (Final), and should run on a wide variety of other Unix/Linux distributions without modification.

See for more details.

Cite As

Jorg Woehl (2021). detectOS (, GitHub. Retrieved .

Comments and Ratings (1)

Ethan Png

MATLAB Release Compatibility
Created with R2013a
Compatible with R2016b and later releases
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!