reset
Class: matlab.task.LiveTask
Namespace: matlab.task
Syntax
reset(obj)
Description
reset( resets the state of the task. It
executes when a user restores the default values of the task by clicking the options button
at the top-right of the task and selecting
Restore Default Values. Define this method in a method block with
no arguments, along with the obj)get.Summary, get.State,
set.State, and generateCode methods.
Input Arguments
Object of the class that inherits from the matlab.task.LiveTask base
class.
Examples
Define a class called DisplayImage that creates a custom Live Editor task for displaying an image.
To define the class, create a file called DisplayImage.m that contains the following class definition with these features:
StateandSummarypublic properties that store the current state of the task and a dynamic summary of what the task does.Private properties that store the edit field and button for selecting an image.
A
setupmethod that initializes the task.A
generateCodemethod that updates the generated code for the task when the selected image changes.get.Summary,get.State, andset.Statemethods for getting and setting the summary and state of the task.An
inputImageFilemethod that prompts the user to select an image to display.A
resetmethod that resets the state of the task.
classdef DisplayImage < matlab.task.LiveTask properties(Access = private,Transient) FileNameEditField matlab.ui.control.EditField BrowseButton matlab.ui.control.Button end properties(Dependent) State Summary end methods(Access = protected) function setup(task) createComponents(task); setComponentsToDefault(task); end end methods function [code,outputs] = generateCode(task) if isempty(task.FileNameEditField.Value) % Return empty values if there is not enough % information to generate code code = ""; outputs = {}; return end outputs = {"im"}; code = ["% Get Image" outputs{1} + " = imread(""" + ... task.FileNameEditField.Value + """);" "" "% Visualize results" "figure" "imshow(" + outputs{1} + ");"]; end function summary = get.Summary(task) if isempty(task.FileNameEditField.Value) summary = "Display selected image"; else [~,name,~] = fileparts(task.FileNameEditField.Value); summary = "Display image '" + name + "'"; end end function state = get.State(task) state = struct; state.FileNameEditFieldValue = task.FileNameEditField.Value; end function set.State(task,state) task.FileNameEditField.Value = state.FileNameEditFieldValue; end function reset(task) setComponentsToDefault(task); end end methods(Access = private) function createComponents(task) task.LayoutManager.RowHeight = ["fit" "fit" "fit"]; task.LayoutManager.ColumnWidth = "fit"; % Row 1: Select image section label uilabel(task.LayoutManager,"Text","Select image", ... "FontWeight","bold"); % Row 2: Select data section components inputgrid = uigridlayout(task.LayoutManager,"RowHeight", ... "fit","ColumnWidth",{"fit",200,"fit"},"Padding",0); uilabel(inputgrid,"Text","Input image"); task.FileNameEditField = uieditfield(inputgrid, ... "Editable",false); task.BrowseButton = uibutton(inputgrid,"Text","Browse", ... "ButtonPushedFcn",@task.inputImageFile); % Row 3: Display results section label uilabel(task.LayoutManager,"Text","Display results", ... "FontWeight","bold"); end function setComponentsToDefault(task) task.FileNameEditField.Value = ""; end function inputImageFile(task,~,~) % Display uigetfile dialog box filterspec = ["*.jpg;*.tif;*.png;*.gif","All Image Files"]; [f,p] = uigetfile(filterspec); % Make sure user did not cancel uigetfile dialog box if (ischar(p)) fileName = [p f]; task.FileNameEditField.Value = fileName; end notify(task,"StateChanged"); end end end
Next, configure the task metadata by calling the matlab.task.configureMetadata function and selecting the DisplayImage.m file. The Task Metadata dialog box opens with all of the required task metadata details prepopulated.

Select OK to use the prepopulated metadata details. MATLAB creates a folder named resources inside the folder containing your task class definition file. Inside the resources folder, MATLAB generates a file named liveTasks.json.
Add the folder containing the task class definition file to the MATLAB path by calling the addpath function or using the Add Folder button in the Set Path dialog box.
Add the task to a live script. On a code line, type display. MATLAB shows a list of suggested matches.

Select Display Image from the list. MATLAB adds the Display Image task to the live script.

Version History
Introduced in R2022a
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)