Main Content

setVariableValue

Class: mlreportgen.report.MATLABVariable
Namespace: mlreportgen.report

Set the value to report for a variable

Since R2020b

Syntax

setVariableValue(rptr,value)

Description

setVariableValue(rptr,value) sets the value of the variable reported by the specified reporter to the specified value and sets the Location property of the reporter to "User-Defined".

Input Arguments

expand all

MATLAB® variable reporter, specified as an mlreportgen.report.MATLABVariable object.

Value to report, specified as any MATLAB data type.

Examples

expand all

This example shows how to report values that are not assigned to variables in the MATLAB® workspace. The example creates a containers.Map object. The Map object is defined in the MATLAB workspace, but the key-value pair entries are not assigned to variables in the workspace. To report on the entries, the example creates a reporter for each entry in the Map object, gets the entry value from the Map object, and then uses setVariableValue to specify the value to report.

Import the Report API namespace so that you do not have to use long, fully qualifed class names.

import mlreportgen.report.*

Create a Map object.

myMap = containers.Map(["key1","key2"],[100,200]);

Create a report.

report = mlreportgen.report.Report("My Report","PDF");

Determine the number of key-value pair entries in the Map object.

n = length(myMap);

Return the keys of the Map object in a cell array.

myKeys = keys(myMap);

Create a reporter for each entry in the Map object. Use setVariableValue to set the value to report for the entry.

for i=1:n
    myKey = myKeys{i};
    rptr = mlreportgen.report.MATLABVariable();
    rptr.Variable = myKey;
    setVariableValue(rptr,myMap(myKey));
    append(report,rptr);
end

Close and view the report.

close(report);
rptview(report);

Here are the key-value pairs in the report:

Version History

Introduced in R2020b