You are reading the article Figure Function In Matlab With Examples updated in October 2023 on the website Cersearch.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 Figure Function In Matlab With Examples
Introduction to Matlab FigureMATLAB provides us with plenty of functionalities, useful in various computational problems. In addition to its computational capabilities, MATLAB is also a great tool for visualization. It provides us with the ability to plot a wide variety of charts. Apart from showing graphical output in the console, MATLAB can also have our graphical output displayed in a separate window. For achieving this, we need to create a ‘figure object’ in MATLAB using figure function, which we will learn in this article.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
Figure function, MATLAB
For creating the figure object, MATLAB creates a separate window. The characteristics of this new window can be controlled using figure properties specified as arguments (Please refer to the end of the article for the custom properties).
Table for Custom PropertiesProperty
Description
Value/s
Color To set the background color Default: As per the color scheme
MenuBar To toggle the menu bar on/off Default: figure
Name To set the title Default: ” (empty string)
number title To display the figure number Default: on
Resize For resizing the figure window using the mouse Default: on
SelectionHighlight To highlight the figure Default: on
Visible Makes figure visible/invisible Default: on
WindowStyle Normal/modal window normal, modal
Default: normal
Syntaxfigure (Name, Value)
We will first understand figure function in its simplest form where we will create a figure & specify the property “Name”.For this example, we will pass “Name” property as ‘Learning figure function’
Examples to Implement Matlab FigureHere are some examples mentioned:
Example #1This is how our input and output will look like in MATLAB console:
Code:
figure ('Name', 'Learning figure function')
Output:
Explanation: As we can observe in the output obtained, we have obtained a new window as a figure object and our figure’s name is as passed by us “Learning figure function”. Also, notice ‘Figure 1’ before the name of the figure, this is done by MATLAB as a default property. However, we can get rid of this.
Example #2Let us learn how to get the name without the figure number. To achieve this, we need to keep the ‘Numbertitle’ property of figure function as ‘off’. This is how our input and output will look like in MATLAB console:
Code:
figure('Name', 'Learning figure function','NumberTitle','off');
Output:
Note: In the output that we have obtained a new window without the figure number.
Example #3
Next we will learn how we can get our graph in the figure object. To get the graph in a new window, we first create the figure object as above and then write the syntax to create the desired plot. MATLAB by default assigns the plot to the latest figure object created.
In our example, we will create a bar plot in the figure object.
X = [12, 20, 13, 40, 40, 23, 54, 65, 11, 40, 70, 45, 60, 33][Input array to create bar plot]
This is how our input and output will look like in MATLAB console:
Code:
X = [12, 20, 13, 40, 40, 23, 54, 65, 11, 40, 70, 45, 60, 33] bar (X)
Output:
Example #4As we can see, our output bar chart is in a new window and with the name as passed by us. We can also change the background of the new window using the ‘Color’ property of figure function. Let us learn how to do that.
For our example, we will set the ‘Color’ property to ‘c’ which is pre-defined color code for the color cyan.
Note: In the above line of code that we have set the ‘Color’ property as ‘c’ to get Cyan color
This is how our input and output will look like in MATLAB console:
Code:
X = [12, 20, 13, 40, 40, 23, 54, 65, 11, 40, 70, 45, 60, 33]
Output:
Explanation: So, we have our output window in CYAN color now.
Example #5Let us take another example where we will create a scatter plot in a new window using figure function. For this example, we will get our background in Red color.
scatter((1:40),and(1,40)); [Creating scatter plot using random values]
As explained earlier, MATLAB will by default plot the graph in the figure object created. This is how our input and output will look like in MATLAB console:
Code:
scatter((1:40),rand(1,40));
Output:
Explanation: As we can see in our output, we have our scatter plot created in a new window, with red color.
Conclusionfigure function in MATLAB is used if we want our plot to be created in a separate window. We can control the look and feel of the new window using the properties of the figure function.
Recommended ArticlesThis is a guide to Matlab Figure. Here we discuss an introduction to Matlab Figure, Table for custom properties, syntax, examples with code and output. You can also go through our other related articles to learn more –
You're reading Figure Function In Matlab With Examples
Update the detailed information about Figure Function In Matlab With Examples on the Cersearch.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!