Updated March 13, 2023
Introduction to Matlab Lists
MATLAB Lists can be ordered, unordered, multi-level, and can be created and formatted using the DOM API in a program that generates a report. A list can be created from an array string in MATLAB, which specifies the items in the list or creates a list with items inserted one by one. It is easy to create a list using an array, creating the list by inserting items one by one is handy when there are multiple elements in the item, like in the case of a table or paragraph.
Syntax:
- In MATLAB, we represent lists as mlreportgen.dom.OrderedList or mlreportgen.dom.UnorderedList objects
- mlreportgen.dom.ListItem objects are used to represent items of the lists
Description:
- mlreportgen.dom.OrderedList is used to create an ordered list
- mlreportgen.dom.UnorderedList is used to create an Unordered or bulleted list
Let us now understand the code to create a list in the MATLAB report.
Examples of Matlab Lists
Lets us discuss the examples of Matlab List.
Example #1
In the first example, we will create an unordered list in a MATLAB report. The list will be created from an array string. Below are the steps that we will follow for this example:
- Import the library mlreportgen.dom.*
- Initialize the document where we want to create the list
- Use the append method to append the document with the list items
Code:
import mlreportgen.dom.*
[Importing the required library]
Doc = Document("Employees", "html");
[Initializing the variable ‘Doc’ and storing the report to be appended in it]
App = append(Doc, ["Tom", "Jack", "Berlin", “Ryan”, “Harris”]);
[Appending the report ‘Employees’ using an array string]
close(Doc);
[Closing the report once it is appended]
rptview(Doc);
[Opening the report “Employees” to check if the list is created]
This is how our input and output will look like in the MATLAB command window:
Input:
import mlreportgen.dom.*
Doc = Document("Employees", "html");
App = append(Doc, ["Tom", "Jack", "Berlin", "Ryan", "Harris"]);
close(Doc);
rptview(Doc);
Output:
As we can see in the OUTPUT, the report “Employees” is now appended with an unordered list as expected.
Example #2
Let us take another example where we create an unordered list in a MATLAB report. The list will be created from an array string. Below are the steps that we will follow for this example:
- Import the library mlreportgen.dom.*
- Initialize the document where we want to create the list
- Use the append method to append the document with the list items
Code:
import mlreportgen.dom.*
[Importing the required library]
Doc = Document("Organization", "html");
[Initializing the variable ‘Doc’ and storing the report to be appended in it]
App = append(Doc, ["TCS", "Reliance Industries", “HCL", “Capgemini”]);
[Appending the report ‘Organization’ using an array string]
close(Doc);
[Closing the report once it is appended]
rptview(Doc);
[Opening the report ‘Organization’ to check if the list is created]
This is how our input and output will look like in the MATLAB command window:
Input:
import mlreportgen.dom.*
Doc = Document("Organization", "html");
App = append(Doc, ["TCS", "Reliance Industries", "HCL", "Capgemini"]);
close(Doc);
rptview(Doc);
Output:
As we can see in the OUTPUT, the report ‘Organization’ is now appended with an unordered list as expected.
In the above 2 examples, we created unordered lists using an array string. Next, we will learn to create an ordered list using an array string.
Example #3
In this example, we will create an ordered list in a MATLAB report. The list will be created from an array string. Below are the steps that we will follow for this example:
- Import the library mlreportgen.dom.*
- Initialize the document where we want to create the list
- Pass the input array string to the Ordered list constructor
- Use the append method to append the document with the list items
Code:
import mlreportgen.dom.*
[Importing the required library]
Doc = Document("Months", "html");
[Initializing the variable ‘Doc’ and storing the report to be appended in it]
NewList= OrderedList(["January", "February", "March", "April", "May"]);
[Creating a new variable and storing an ordered list in it]
append(Doc, NewList);
[Appending the report ‘Months’ using ‘NewList’ created in above step]
close(Doc);
[Closing the report once it is appended]
rptview(Doc);
[Opening the report ‘Months’ to check if the list is created]
This is how our input and output will look like in the MATLAB command window:
Input:
import mlreportgen.dom.*
Doc = Document("Months", "html");
NewList = OrderedList(["January", "February", "March", "April", "May"]);
append(Doc, NewList);
close(Doc);
rptview(Doc);
Output:
As we can see in the OUTPUT, the report ‘Months’ is now appended with an ordered list as expected.
Example #4
In this example, we will create another ordered list in a MATLAB report. The list will be created from an array string. Below are the steps that we will follow for this example:
- Import the library mlreportgen.dom.*
- Initialize the document where we want to create the list
- Pass the input array string to the Ordered list constructor
- Use the append method to append the document with the list items
Code:
import mlreportgen.dom.*
[Importing the required library]
Doc = Document("Countries", "html");
[Initializing the variable ‘Doc’ and storing the report to be appended in it]
NewList= OrderedList(["India", "Australia", "Japan", "USA", "UK"]);
[Creating a new variable and storing an ordered list in it]
append(Doc, NewList);
[Appending the report ‘Countries’ using ‘NewList’ created in above step]
close(Doc);
[Closing the report once it is appended]
rptview(Doc);
[Opening the report ‘Countries’ to check if the list is created]
This is how our input and output will look like in the MATLAB command window:
Input:
import mlreportgen.dom.*
Doc = Document("Countries", "html");
NewList = OrderedList(["India", "Australia", "Japan", "USA", "UK"]);
append(Doc, NewList);
close(Doc);
rptview(Doc);
Output:
As we can see in the OUTPUT, the report ‘Countries’ is now appended with an ordered list as expected.
Conclusion
mlreportgen.dom.OrderedList is used to create an ordered list in MATLAB. mlreportgen.dom.UnorderedList is used to create an Unordered or bulleted list in MATLAB. The items can be added to the list created using an array string.
Recommended Articles
This is a guide to Matlab Lists. Here we discuss the introduction to the Matlab Lists, syntax, examples with code implementation respectively. You may also have a look at the following articles to learn more –