You are reading the article A Quick Glance Of Matlab Annotation With Examples updated in October 2023 on the website Saigonspaclinic.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 A Quick Glance Of Matlab Annotation With Examples
Introduction to Matlab AnnotationAnnotating a graph or any document is a very important way to help the readers to understand better context & the argument presented by the graph or document and also to facilitate their understanding of how they should read the graph (or document). Using annotation, we provide any extra information related to the graph that readers might find useful while interpreting the graph. In Matlab, we use ‘annotation’ function for creating various types of annotations.
Start Your Free Data Science Course
Hadoop, Data Science, Statistics & others
We have 2 types of annotations in Matlab:
Line Type
Shape Type
Syntax:
annotation (lineType, A, B)
annotation (shapeType, dim)
Description:
annotation (lineType, a, b): It is used to create an arrow or a line annotation. This annotation is extended between the 2 points in the figure.
annotation (shapeType, dim): It creates a shape annotation of defined size and location.
The ‘lineType’ argument can take the following 4 values:
Line
Arrow
Double Arrow
Text Arrow
The ‘shapeType’ argument can take the following values:
Rectangle
Textbox
Examples of Matlab AnnotationGiven below are the examples mentioned:
Example #1We will follow the following steps:
Create the sine plot.
Initialize the points for the annotation line.
Pass these points as arguments to the annotation function.
Code:
Fs = 0:pi/50:2*pi;
[Defining the frequency for sinewave]
[Defining the frequency for sinewave]
y = sin(Fs);
[Initializing the sine wave]
[Initializing the sine wave]
plot(Fs,y)
[Creating the plot of sine wave]
[Creating the plot of sine wave]
A = [0.3 0.3];
B = [0.8 0.9];
[Defining the points for the annotation]
[Defining the points for the annotation]
annotation(‘line,’ A, B)
[Passing the above points to the annotation function]
[Passing the above points to the annotation function]
Input:
annotation(‘line’, A, B)
Output:
As we can see in the output, the first peak of the sine wave is being pointed out using an annotation line.
Example #2In this example, we will use the arrow annotation to show the first incident when our sine wave touches the maximum value.
Code:
Fs = 0:pi/50:2*pi;
[Defining the frequency for sinewave]
[Defining the frequency for sinewave]
y = sin(Fs);
[Initializing the sine wave]
[Initializing the sine wave]
plot(Fs,y)
[Creating the plot of sine wave]
[Creating the plot of sine wave]
A = [0.3 0.3];
B = [0.8 0.9];
[Defining the points for the annotation]
[Defining the points for the annotation]
annotation(‘arrow,’ A, B)
[Passing the above points to the annotation function. Please note that the first argument in this case is ‘arrow’]
[Passing the above points to the annotation function. Please note that the first argument in this case is ‘arrow’]
Input:
annotation(‘arrow’, A, B)
Output:
As we can see in the output, the first peak of the sine wave is being pointed out using an annotation arrow.
Example #3In this example, we will use the double arrow annotation to show the first incident when our sine wave touches the maximum value.
Code:
[Defining the frequency for sinewave]
[Defining the frequency for sinewave]
y = sin(Fs);
[Initializing the sine wave]
[Initializing the sine wave]
plot(Fs,y)
[Creating the plot of sine wave]
[Creating the plot of sine wave]
A = [0.3 0.3];
B = [0.8 0.9];
[Defining the points for the annotation]
[Defining the points for the annotation]
annotation(‘doublearrow,’ A, B)
[Passing the above points to the annotation function. Please note that the first argument, in this case, is ‘doublearrow’]
[Passing the above points to the annotation function. Please note that the first argument, in this case, is ‘doublearrow’]
Input:
annotation(‘doublearrow’, A, B)
Output:
As we can see in the output, the first peak of the sine wave is being pointed out using an annotation double arrow.
All the above annotation types help us to put a line or arrow, but what if we need text also along with the annotation line? For this purpose, we use ‘textarrow’ annotation.
Example #4In this example, we will use the text arrow annotation to show the first incident when our sine wave touches the maximum value.
Code:
Fs = 0:pi/50:2*pi;
[Defining the frequency for sinewave]
[Defining the frequency for sinewave]
y = sin(Fs);
[Initializing the sine wave]
[Initializing the sine wave]
plot(Fs,y)
[Creating the plot of sine wave]
[Creating the plot of sine wave]
A = [0.3 0.3];
B = [0.8 0.9];
[Defining the points for the annotation]
[Defining the points for the annotation]
messageToDisplay = ‘First Maxima’
[Initializing the string with text message]
[Initializing the string with text message]
annotation(‘textarrow,’ A, B, ‘String’, str)
[Passing the above points to the annotation function. Please note that the first argument, in this case, is ‘textarrow’.
We have also passed the string with a message to be displayed]
Input:
annotation(‘textarrow’, A, B, ‘String’, messageToDisplay)
Output:
As we can see in the output, the first peak of the sine wave is being pointed, and we also have a text message displayed.
Example #5In this example, we will use the textbox annotation, which is a shapetype annotation.
Code:
Fs = 0:pi/50:2*pi;
[Defining the frequency for sinewave]
[Defining the frequency for sinewave]
y = sin(Fs);
[Initializing the sine wave]
[Initializing the sine wave]
plot(Fs,y)
[Creating the plot of sine wave]
[Creating the plot of sine wave]
boxDimension = [0.5 0.5 0.3 0.3];
[Defining the points for the annotation]
[Defining the points for the annotation]
messageToDisplay = ‘Let us learn annotation’
[Initializing the string with text message]
[Initializing the string with text message]
annotation(‘textbox’, boxDimension, ‘String’, messageToDisplay, ‘FitBoxToText,’ ‘on’);
[Passing the above points to the annotation function. Please note that the first argument in this case is ‘textbox’]
[Passing the above points to the annotation function. Please note that the first argument in this case is ‘textbox’]
Input:
annotation(‘textbox’, boxDimension, ‘String’, messageToDisplay, ‘FitBoxToText’, ‘on’);
Output:
As we can see in the output, our plot has an annotation in the form of a text box with the required message.
To get a simple rectangle as annotation, change the argument from ‘textbox’ to ‘rectangle’ in the above code and remove other arguments.
ConclusionAnnotation is done to make our plot more readable and intuitive. Any additional information that we want the reader to have about our graph can be passed as an annotation. Matlab provides us with various annotation types like line, arrow, textbox, etc.
Recommended Articles
This is a guide to Matlab Annotation. Here we discuss the introduction to Matlab Annotation along with programming examples. You may also have a look at the following articles to learn more –
You're reading A Quick Glance Of Matlab Annotation With Examples
Update the detailed information about A Quick Glance Of Matlab Annotation With Examples on the Saigonspaclinic.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!