MATLAB Answers

How do I use live script (*.mlx) files in source control?

133 views (last 30 days)
I would like to use the live script files with source control, what is the workflow for that?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 23 Jun 2017
It is possible to use source control with live scripts, the following points should be kept in mind:
  • Tell the source control system that files ending in .mlx are binary
  • Use the built in MATLAB file differencing tool to compare live scripts
  • Merging is currently limited to manual

  4 Comments

Show 1 older comment
Simon Silge
Simon Silge on 14 Aug 2020
As Steven Lord has correctly written below you can now customize your source control system to use the MATLAB diff and merge tool as explained on this page. Also, source control is now integrated into the MATLAB surface, the doc page is here. There is also a quick introduction video.
Vasco
Vasco on 13 Oct 2020
From what I understand until now is that there are two kind of contents in a mlx file:
  1. Text input (code, text blocks). These are all pure text. This is very important to keep under version control.
  2. Output blocks, which can contain anything including figures and movies. This can be a lot of data, and is typically not very important to have under version control.
Why not have include 1 as plain text in the mlx file, and add 2 as zipped and base64 encoded (or a utf8/utf16 equivalent like that) on separated lines? This way code reviewing can be done with standard tools (like bitbucket). The main thing that can happen is that a code cell gets two outputs (instead of one). The live editor could detect this and show a warning.
With this file format is is also relativity easy to create a mlx file without output.
Walter Roberson
Walter Roberson on 13 Oct 2020
Why not have include 1 as plain text in the mlx file, and add 2 as zipped and base64 encoded
The use case for mlx files is that the user should only have to copy one file and that would bring all relevant parts with it. This is the same strategy as for Simulink .slx files.
.mlx files are zip files that are mostly XML files, using the same kind of directory structure used by Microsoft .xlsx files -- OpenXML structures.
Any inserted code or text or controls are encoded as xml.
Any inserted equations are primarily encoded as xml, but a mathml equivalent of them is also included.
Any inserted images have coded by relationship identifiers, and the appropriate .rels file (which is more XML but with a different extension) gives a directory reference to a binary copy of the image -- the image itself is included in the .mlx structure, not just a filename reference to the image.
You could potentially compare by unzip the .mlx file and comparing files. You might, however, have some difficulty with relationship identifiers being different -- I see no attempt in the files to allocate a GUID to relationships so as to be able to compare them even if you did something like insert a new control in the middle.

Sign in to comment.

More Answers (4)

Teemu Sillanpää
Teemu Sillanpää on 22 Mar 2018
So with the change from readable content (text) to binary, live scripts / to achieve .m files with documentation built in feature is totally useless in normal working environment (>1 user).

  0 Comments

Sign in to comment.


Markus Leuthold
Markus Leuthold on 1 Apr 2019
This is going into a completely wrong direction. Source code files must be text files. The toolchain does not only consist of Matlab, but many other such aus Github etc... which become unusable with these mlx files.
Unfortunately, there are already new features which are only available in the Live editor, but not in the classic editor or command window, such as tab completion via functionSignatures.json

  1 Comment

Walter Roberson
Walter Roberson on 1 Apr 2019
I used to rail against web pages with images because "Source code files must be text files!", and you couldn't copy and paste the representation of images. I lost that fight, Tools evolved.
I also appear to have lost the fight against CSS...

Sign in to comment.


Richard Crozier
Richard Crozier on 21 Mar 2018
Edited: Richard Crozier on 21 Mar 2018
No you cannot use live scripts with any of the major version control systems such as svn, git or mercurial. They are a binary format and not compatible with these text difference based systems. Versioning the files will be possible in a very basic sense but none of the standard diffing and merging commands will work effectively, and none of the standard GUI tools for comparing versions will work as the files will simply appear as binary blobs.
You may be able to set up your source control system on one or two machines to work as specified in the Matlab docs, but no remote services such as Github or Bitbucket will support this.

  0 Comments

Sign in to comment.


Teemu Sillanpää
Teemu Sillanpää on 10 Jan 2018
Has this "readable content being source controlled as binary" been fixed already?
The whole idea of readable code is the ability to commit/diff changes in readable form in source controlled environment. Now zipping the .XML to a .xml without the source control understanding the nature of the content is purely wrong approach. Live scripts can be written/converted also in .m but this is not intuitive process in the GUI environment - ending up having two source controlled files (risk of being unsync) between .m and .mlx. Third option would be that Mathworks provides GIT tools which understand the .mlx as readable content. Or the .mlx files being converted to ASCII (.m ish) before source controlled.
Any of these properties implemented yet in the R2017b or coming R2018a?

  2 Comments

Walter Roberson
Walter Roberson on 10 Jan 2018
"Any of these properties implemented yet in the R2017b or coming R2018a?"
No. It is unlikely that the representation as a zip'd series of xml files will be changed any time soon.
Steven Lord
Steven Lord on 10 Jan 2018
As of release R2016b you can customize your source control system to use the diff and merge tools included in MATLAB for binary .mlx files. See this page in the documentation for instructions on how to configure your system.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!