How to export vairable from Live Task to Workspace
Show older comments
I want to develope my own Live Task for Matlab Live Editor. However I faced one problem, which is not explained in documentations (or at least I can''t find it). I want o export value from the task, back to main workspace, so it could be used by user later in .mlx file. Here is very simple example of the task, to keep it clear. It contains only one EditField and I want to export the value typed in this field back to the workspace. How to do this?
classdef TEST_exported < matlab.task.LiveTask
% Properties that correspond to task components
properties (Access = public)
GridLayout matlab.ui.container.GridLayout
EditField matlab.ui.control.NumericEditField
EditFieldLabel matlab.ui.control.Label
end
properties(Dependent)
State
Summary
end
% Component initialization
methods (Access = private)
% Create UIFigure and components
function createComponents(task)
% Create GridLayout
fig = task.LayoutManager;
task.GridLayout = uigridlayout(fig);
task.GridLayout.ColumnWidth = {'1x', '1x', '1x'};
task.GridLayout.RowHeight = {'1x', '1x', '1x', '1x', '1x', '1x', '1x', '1x'};
% Create EditFieldLabel
task.EditFieldLabel = uilabel(task.GridLayout);
task.EditFieldLabel.HorizontalAlignment = 'right';
task.EditFieldLabel.Layout.Row = 3;
task.EditFieldLabel.Layout.Column = 1;
task.EditFieldLabel.Text = 'Edit Field';
% Create EditField
task.EditField = uieditfield(task.GridLayout, 'numeric');
task.EditField.Layout.Row = 3;
task.EditField.Layout.Column = 2;
end
end
methods(Access = protected)
function setup(task)
createComponents(task);
end
end
methods
function [code,outputs] = generateCode(task)
code = "";
outputs = {''};
end
function summary = get.Summary(task)
summary = "";
end
function state = get.State(task)
state = struct;
end
function set.State(task,state)
end
function reset(task)
end
end
end
I can do it "dummy way" by adding:
state.Field=task.EditField.Value;
save state state;
To the get.State function, and load it back from state.mat file after live task/;
load state
But it is workaround, not real solution.
Accepted Answer
More Answers (0)
Categories
Find more on Workspace Variables and MAT Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!