主要内容

Add Interactive Tasks to a Live Script

什么是现场编辑任务?

Live Editor tasks are apps that can be added to a live script to perform a specific set of operations. You can add tasks to live scripts to explore parameters and automatically generate code. Use tasks to reduce development time, errors, and time spent plotting.

Tasks represent a series of MATLAB®commands. You can display their output either inline or on the right. To see the MATLAB commands that the task runs, show the generated code.

Insert Tasks

To add a task to a live script, go to theLive Editortab, clickTask, and select from the available tasks. You also can type the name of the task in a live script code block. As you type, the Live Editor displays possible matches, and you can select and insert the desired task. For example, create a live script that creates a vector of data containing an outlier.

A = [57 59 60 100 59 58 57 58 300 61 62 60 62 58 57];

Add the创造情节任务你住脚本to plot the vector of data.

Add theClean Outlier Data任务你住脚本to smooth the noisy data and avoid skewed results. To add the task, start typing the word干净的in the live script and selectClean Outlier Datafrom the suggested command completions. In the task, set输入数据toA。The task identifies and fills two outliers in the data and creates the variablecleaneddata.在MATLAB工作区与存储的结果。您还可以在输出绘图中看到任务的结果。继续修改其他参数,直到您对结果满意。

Restore Default Parameters

To restore all parameter values back to their defaults, click the options button在任务的右上角并选择Restore Default Values

Collapse Tasks for Improved Readability

完成修改参数后,您可以折叠任务以帮助可读性。要折叠任务,请单击任务左上角的箭头。

The task displays as a single, user-readable line of pseudocode with output.

删除Tasks

To delete a task, click the task and then press删除或者Backspace。您还可以在任务之前或之后直接放置光标并使用删除或者Backspacekey, respectively.

Run Tasks and Surrounding Code

By default, as you modify the value of parameters in the task, the task and current section (including other tasks in the section) run automatically. This ensures that the results and surrounding code in the section remain up to date. For example, in the live script干净的mydata.mlx,整个部分,包括在每次修改清洁异常数据任务中的参数的值时创建噪声数据reeruns的代码。仅运行任务,在任务之前和之后添加部分中断。有关部分的更多信息以及如何添加部分中断,请参阅Run Sections in Live Scripts

A green circular icon at the top-right of the task indicates that the task runs automatically when you modify the task parameters.

To disable running the section automatically, click the autorunicon. The icon updates to display the disabled state. To run the task and current section, on theLive Editortab, click theRun Sectionbutton.

Some tasks do not run automatically by default. This default setting ensures optimal performance for those tasks.

Modify Output Argument Name

要修改输出参数的名称,请单击包含参数名称的文本框,然后输入新名称。

You can use the resulting output argument in subsequent code, including as inputs to additional Live Editor tasks.

View and Edit Generated Code

要查看任务运行的MATLAB命令,请单击“选项”按钮在任务的右上角并选择eitherControls and Code或者Code Only。You also can use the down arrow at the bottom of the task to show and hide the generated code. The generated code is read-only.

To edit the generated code, click the options buttonand selectConvert Task to Editable Code。This option removes the task and replaces it with the generated code, which you then can edit.

相关话题