主要内容

convertmupadnotebook

Convertmupadnotebook toMATLABlive script

描述

example

convertmupadnotebook(mupadfile,MATLABLiveScript)converts a MuPAD®notebook filemupadfile(.mn) to a MATLAB®live script fileMATLABLiveScript(.mlx). BothmupadfileMATLABLiveScriptmust be full paths unless the files are in the current folder. For information on live scripts, see在实时编辑器中创建实时脚本.

example

convertmupadnotebook(mupadfile)uses the same name and path,mupadfile, for the MATLAB live script file that contains converted code. The extension.mn更改.mlx在生成的MATLAB实时脚本文件中。

例子

ConvertmupadNotebook toMATLAB脚本

Usingconvertmupadnotebook, convert a MuPAD notebook to a MATLAB live script. Alternatively, right-click the notebook in the Current Folder browser and selectOpen as Live Script从上下文菜单。

假设您当前的文件夹包含一个名为Mupad笔记本mynotebook.mn. Convert this notebook to the MATLAB live script file namedmyScript.mlx.

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

Open the resulting file.

edit('myScript.mlx')

视觉检查代码的正确性和完整性。然后通过运行它来验证它。

使用相同的名称进行转换的文件

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

假设您当前的文件夹包含一个名为Mupad笔记本myFile.mn. Convert this notebook to the MATLAB live script file namedmyFile.mlx.

convertmupadnotebook(“myFile.mn”)

Open the resulting file.

edit('myFile.mlx')

视觉检查代码的正确性和完整性。Then verify it by executing it.

Fix Translation Errors or Warnings

如果convertmupadnotebookreports 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. Becausemynotebook.mn包含无法直接翻译为MATLAB代码的命令,convertmupadnotebook将这些命令标记为翻译错误和警告。

convertmupadnotebook('myNotebook.mn','myScript.mlx')
创建的“ myScript.mlx”:4个翻译错误,1个警告。要验证...文档,请参阅帮助。ans = c:\ matlabscripts \ myscript.mlx

翻译错误表明convertmupadnotebookwas unable to convert part of the MuPAD notebook, and that without this part the translated code will not run properly. A translation warning indicates thatconvertmupadnotebook无法转换Mupad笔记本的一部分(例如,一个空输入区域)并忽略了它。包含警告的转换代码很可能没有任何问题。

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.

视觉检查代码的正确性和完整性。

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 theconvertmupadnotebook功能on on every notebook in the folder.

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

ConvertmupadProcedure toMATLAB功能

convertmupadnotebook将Mupad过程转换为MATLAB函数。并非所有mupad过程都可以转换。

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

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

The output ofconvertmupadnotebookis a live script with the anonymous functionf.

For details on anonymous functions, seeAnonymous 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- >ifx=1then2else3endF(0)

The procedure is too complex to convert to an anonymous function. The output ofconvertmupadnotebookis a live script with the local functionaux2.

有关脚本中本地功能的信息,请参阅将功能添加到脚本.

转换读取mupad程序文件的笔记本时(.mu),convertmupadnotebook替换command with the contents of the.mufile. The notebook and program files must be in the same directory.

Input Arguments

全部收缩

Mupad笔记本的名称,指定为字符向量。除非文件在当前文件夹中,否则此字符向量必须指定文件的完整路径。

例子:'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.

例子:'C:\MATLAB_Scripts\myFile.mlx'

Version History

Introduced in R2016a