Main Content

convertMuPADNotebook

(To be removed) Convert MuPAD notebook to MATLAB live script

convertMuPADNotebook will be removed in a future release. Convert your MuPAD® notebooks to MATLAB® live scripts now, and use the MATLAB Live Editor instead.

Description

example

convertMuPADNotebook(MuPADfile,MATLABLiveScript) converts a MuPAD notebook file MuPADfile (.mn) to a MATLAB live script file MATLABLiveScript (.mlx). Both MuPADfile and MATLABLiveScript must be full paths unless the files are in the current folder. For information on live scripts, see Create Live Scripts in the Live Editor.

example

convertMuPADNotebook(MuPADfile) uses the same name and path, MuPADfile, for the MATLAB live script file that contains converted code. The extension .mn changes to .mlx in the resulting MATLAB live script file.

Examples

Convert MuPAD Notebook to MATLAB Script

Using convertMuPADNotebook, convert a MuPAD notebook to a MATLAB live script. Alternatively, right-click the notebook in the Current Folder browser and select Open as Live Script from the context menu.

Suppose that your current folder contains a MuPAD notebook named myNotebook.mn. Convert this notebook to the MATLAB live script file named myScript.mlx.

convertMuPADNotebook('myNotebook.mn','myScript.mlx')

Open the resulting file.

edit('myScript.mlx')

Visually check the code for correctness and completeness. Then verify it by running it.

Use Same Name for Converted File

Convert a MuPAD notebook to a MATLAB live script file with the same name.

Suppose that your current folder contains a MuPAD notebook named myFile.mn. Convert this notebook to the MATLAB live script file named myFile.mlx.

convertMuPADNotebook('myFile.mn')

Open the resulting file.

edit('myFile.mlx')

Visually check the code for correctness and completeness. Then verify it by executing it.

Fix Translation Errors or Warnings

If convertMuPADNotebook reports that the converted code has translation errors or warnings, correct the resulting MATLAB code before using it.

Convert the MuPAD notebook, myNotebook.mn, to the MATLAB live script file, myScript.mlx. Because myNotebook.mn contains commands that cannot be directly translated to MATLAB code, convertMuPADNotebook flags these commands as translation errors and warnings.

convertMuPADNotebook('myNotebook.mn','myScript.mlx')
Created 'myScript.mlx': 4 translation errors, 1 warnings. For verifying...
 the document, see help.
ans =
c:\MATLABscripts\myScript.mlx

A translation error indicates that convertMuPADNotebook was unable to convert part of the MuPAD notebook, and that without this part the translated code will not run properly. A translation warning indicates that convertMuPADNotebook was unable to convert a part of the MuPAD notebook (for example, an empty input region) and ignored it. Converted code containing warnings is likely to run without any issues.

Open the resulting file.

edit('myScript.mlx');

Eliminate translation errors. First, search for “translation error”. Next to “translation error”, the converted code displays short comments explaining which MuPAD command did not translate properly. There is also a link to documentation that provides more details and suggestions for fixing the issue. After fixing the issue, remove the corresponding error message and any comments related to it.

Find translation warnings by searching for “translation warning”. The converted code displays a short comment and a link to documentation next to “translation warning”. Some warnings might require you to adapt the code so it runs properly. In most cases, you can ignore translation warnings. Whether you fixed the code or decided to ignore the warning, remove the warning message and any comments related to it.

Visually check the code for correctness and completeness.

Verify that the resulting MATLAB code runs properly by executing it.

Convert All Notebooks in a Folder

Convert all MuPAD notebooks in a folder by making it your current folder, and then using a loop to call the convertMuPADNotebook function on every notebook in the folder.

files = dir('*.mn');
for i = 1:numel(files)
    convertMuPADNotebook(files(i).name)
end

Convert MuPAD Procedure to MATLAB Function

convertMuPADNotebook converts MuPAD procedures to MATLAB functions. Not all MuPAD procedures can be converted.

Simple procedures are converted into anonymous functions. Convert a MuPAD notebook with the following code.

f := x -> x^2
f(2)

The output of convertMuPADNotebook is a live script with the anonymous function f.

For details on anonymous functions, see Anonymous Functions.

When procedures are too complex to convert to anonymous functions, they are converted to local functions in the live script. Local functions are placed at the end of the live script.

Convert a MuPAD notebook with the following code.

x -> if x=1 then 2 else 3 end
f(0)

The procedure is too complex to convert to an anonymous function. The output of convertMuPADNotebook is a live script with the local function aux2.

For information on local functions in scripts, see Add Functions to Scripts.

When converting a notebook that reads a MuPAD program file (.mu), convertMuPADNotebook replaces the read command with the contents of the .mu file. The notebook and program files must be in the same directory.

Input Arguments

collapse all

Name of a MuPAD notebook, specified as a character vector. This character vector must specify the full path to the file, unless the file is in the current folder.

Example: 'C:\MuPAD_Notebooks\myFile.mn'

Name of a MATLAB live script file, specified as a character vector. This character vector must specify the full path to the file, unless you intend to create a file in the current folder.

Example: 'C:\MATLAB_Scripts\myFile.mlx'

Version History

Introduced in R2016a

expand all

R2023a: Warns

The convertMuPADNotebook function issues a warning that it will be removed in a future release.