How to retrieve the Matlab Release version of simulink file using python

5 views (last 30 days)
Hi, I want to know if there is an API or any method to know in which version of Matlab a simulink file has been developed without opening Matlab.
I have 100+ simulink files and I want to know in which version these files have been developed. All files are created after Matlab 2017.
I am using Python to parse through all models and looking for some mechanism/idea by which we get the matlab version.
Is there any metadata informatio present .slx files.
Thanks in advance.

Answers (1)

Meet
Meet on 10 Jan 2025
Edited: Meet on 10 Jan 2025
Hi Shrirang,
There are two ways in which ways you can get to know the version of the MATLAB used to create Simulink file.
1) Using File Explorer in Windows:-
  • Right Click on the ".slx" file.
  • Click on Properties.
  • Go to the Details tab, there you would find a property named "Version number" which denotes the MATLAB version used to create the simulink file.
2) Simulink ".slx" files adhere to the Open Packaging Conventions (OPC), which are ZIP-based:-
  • The script uses Python's zipfile module to treat the ".slx" file like a ZIP archive and access its contents.
  • Inside the archive, there is a file named "metadata/coreProperties.xml". The script reads this file to find the version information.
  • Using XML parsing, it looks for the version tag and retrieves the version number.
import zipfile
import xml.etree.ElementTree as ET
def get_matlab_version(file_path):
with zipfile.ZipFile(file_path, 'r') as z:
with z.open('metadata/coreProperties.xml') as f:
tree = ET.parse(f)
root = tree.getroot()
for elem in root.findall('.//{http://schemas.openxmlformats.org/package/2006/metadata/core-properties}version'):
return elem.text
file_path = "C:\\Users\\mdp\\Downloads\\modeltest.slx"
version = get_matlab_version(file_path)
print(f"MATLAB Version: {version}")
For more information on how Simulink files are stored, refer to this documentation: https://www.mathworks.com/help/simulink/ug/save-models.html
I hope this helps!!

Community Treasure Hunt

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

Start Hunting!