Today I’d like to introduce a guest blogger, David Garrison, who is a MATLAB Product Manager here at MathWorks. Dave will talk about the new feature introduced in R2019b called Live Editor Tasks which allow you to complete steps in your workflow interactively from within the Live Editor.
Hello everyone. Loren has been kind enough to let me use her blog to tell you about an exciting new feature we've introduced in the Live Editor for R2019b.
Live Editor Tasks are apps that you can embed in your live script that allow you to interactively complete steps in your workflow. Using a Live Editor Task, you can explore parameters and options, see the results immediately, and generate the underlying MATLAB code.
Let's look at an example. I'll talk about the details of how Live Editor Tasks work after I walk through the example.
Suppose I have some electrocardiogram data and I want to analyze it and use MATLAB to calculate a heart rate. I will start with a live script that loads the data and plots it.
I know that the signal is measured by electrodes attached to the skin and it is sensitive to disturbances such as power source interference and noises due to movement. In this case, the signal shows a baseline shift that I want to remove. How do I do that? I might start by typing a keyword to see what kind of suggestions MATLAB will provide. If I type the keyword detrend, I see two options -- the detrend function and something else -- a Live Editor Task called Remove Trends.
If I select the Remove Trends Task, a small app appears in my script.
Now, I can use this Live Editor Task to remove the baseline shift from my data. I select my input data, noisyECG, and a few parameters for the trend I want to remove and voila! I get a new variable, detrendedECG, and a visualization of the original and detrended data. I can also see the underlying MATLAB code that the Live Editor Task has generated for me that performs the detrending step and creates the plot. That's the power of Live Editor Tasks!
Now, I want to identify the peaks in the ECG signal and use the location of those peaks to calculate a heart rate. One of the great things about Live Editor Tasks is that you can combine them with other Live Editor Tasks and with code that you have written yourself. Here, I'll use the Find Local Extrema Task to find the peaks.
I used the output variable, detrendedECG, from the Remove Trends Task as input to the Find Local Extrema Task. Then I set the Min. prominence value to get the peaks I want. Finally, I add some code after the Live Editor Task to calculate the heart rate (lines 32-34)
There! I've completed my analysis with two Live Editor Tasks and a few lines of code. I can now share my analysis with my colleagues and let them experiment with my code.
Now that you have seen Live Editor Tasks in action, let's look at some of the details about how they work. A Live Editor Task has three parts -- the header, the controls, and the generated code.
The header section contains a summary of what the Live Editor Task does.
In this case, it removes a 5th order polynomial trend from my noisyECG data. The box on the left-hand side contains the name of the variable that will be created (or updated) in the MATLAB workspace when the Live Editor Task runs. You can change that variable to be anything you want. I've called it detrendedECG. You can also collapse the task to show only the header.
The controls section contains a set of user interface controls that allow you to explore parameters and options for the Live Editor Task.
The first step is to select the data. In this case, I want to remove an unwanted trend from my noisyECG data. I can then choose the polynomial degree of the trend to be removed. The Breakpoints dropdown allows me to apply the operation to different segments of my data. Finally, I can choose what I want to visualize in the results.
The generated code section shows the code that is created by the Live Editor Task.
This is the code that runs when the Live Editor Task executes. It includes the code to detrend the data and plot the results. The code is automatically updated when parameters in the controls section are changed. By default, the code is hidden but you can see it using the Show Code button just below the controls section.
You don't have to do anything to run a Live Editor Task. Once you specify the input data, the Live Editor Task will run automatically whenever you change one of the values in the controls section. When autorun is set, the Live Editor will run all the code in the section that contains the Live Editor Task. You can turn off autorun by clicking on the green circle in the top, right corner of the header section. Clicking the green circle again will turn autorun back on. When autorun is turned off, you can still run the section using the run bar in the left margin or by clicking on the Run Section button in the toolstrip.
There are two ways to find Live Editor Tasks. You can type a keyword in a code section like I did in the example above or you can find Live Editor Tasks from the toolstrip. The Task dropdown displays a gallery of all the available Live Editor Tasks.
In R2019b, there are 14 Live Editor Tasks. The Data Preprocessing Tasks are available in MATLAB. The others are available with the Control Systems, Predictive Maintenance, and Systems Identification toolboxes, respectively.
There are several options to control how a Live Editor Task is displayed in a live script.
To get this menu, use the options dropdown in the top, right corner of the header section. You can choose to display the controls, the generated code or both. This menu has other useful options as well. For example, you can restore the default values in the controls section or convert the entire Live Editor Task into code that you can edit.
This is just the beginning for Live Editor Tasks! In R2019b, we have shipped an initial set. In subsequent releases, we will add Live Editor Tasks for other workflows. If you have ideas about MATLAB or toolbox functions that might make a good Live Editor Task, please let us know!
Have you discovered Live Editor Tasks in R2019b? Which ones have you used? Do you have any ideas about new Live Editor Tasks? I'd love to hear your thoughts here.
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。