banner



How To Set Step Size In Matlab Plot

Matlab xticks

Introduction to Matlab xticks

The 'xticks function' is used in Matlab to assign tick values & labels to the 10-axis of a graph or plot. By default, the plot function (used to draw any plot) in Matlab creates ticks as per the default scale, merely we might demand to accept ticks based on our requirement. Adding ticks as per our need and labelling them make the plots more intuitive and easier to understand. For this, we can apply the xticks function along with the xticklabels function in Matlab to identify the values of our option on the plots easily.

Syntax of xticks function:

xticks (A)

xticks (A : B : C)

Explanation:

  • xticks (A) is used to fix the ticks defined by the vector A. Delight notation that A must accept values in the ascending gild.
  • xticks (A: B: C) is used to set the ticks defined past the range A: C, with a B gap between the ticks.

Examples of Matlab xticks

Given below are the examples of Matlab xticks:

Case #1

In this instance, we will use the plot function to plot a sine wave and then will set the ticks for information technology using the xticks function.

Below are the steps to be followed:

  • Write the code to create a sine wave.
  • Use the xticks function to fix the ticks for the x-axis.
  • Use the xticklabels part to prepare the labels for the ticks defined in the above pace.

Code:

A = 0 : pi/fifty : ii*pi;
[Initializing the range for sine wave]

B = sin (A);
[Initializing the sine wave]

plot (A, B)
[Using the plot function to plot the sine moving ridge]

xticks ([0 iii vi])
[Using the xticks office to set the ticks for the x-axis]

xticklabels ({'A = 0′,'A = 3′,'A = 6'})
[Using the xticklabels part to set the labels for the ticks]

Input:

Matlab xticks 1

Output:

plot a sine wave

Equally we tin can see in the output, we take obtained ticks of our choice, i.e. 0, 3, 6, using the xticks function. We have also set the labels for these ticks using the xticklabels function.

Example #2

In this example, we will use the plot function to plot a cos wave and so will set the ticks for it using the xticks function.

Beneath are the steps to be followed:

  • Write the lawmaking to create a cos wave.
  • Use the xticks function to gear up the ticks for the x-axis.
  • Employ the xticklabels function to prepare the labels for the ticks divers in the higher up pace.

Lawmaking:

A = 0 : pi/100 : three*pi;
[Initializing the range for cos wave]

B = cos (A);
[Initializing the cos wave]

plot (A, B)
[Using the plot role to plot the cos moving ridge]

xticks ([0 iii 6 nine])
[Using the xticks function to set the ticks for the ten-axis]

xticklabels ({'A = 0′,'A = three′,'A = half dozen', 'A = nine'})
[Using the xticklabels function to set the labels for the ticks]

Input:

Matlab xticks 3

Output:

plot a cos wave

Equally nosotros can see in the output, we accept obtained ticks of our choice, i.due east. 0, three, half dozen, ix, using the xticks part. We accept also set the labels for these ticks using the xticklabels function.

In the above two examples, we accept passed all the values which we desire to set as the ticks of a plot equally arguments to the xticks function.

Next, we will come across how to prepare a range of values with a fixed interval as the ticks of a plot.

Example #3

In this example, nosotros volition use the plot function to plot a sine wave and so will set the ticks for it past passing a range as an argument to the xticks function.

Beneath are the steps to be followed:

  • Write the code to create a sine wave.
  • Employ the xticks part to fix the ticks for the x-centrality.
  • Use the xticklabels function to set the labels for the ticks divers in the above step.

Code:

A = linspace (0, fifty)
[Initializing the range for sine moving ridge]

B = sin (A);
[Initializing the sine wave]

plot (A, B)
[Using the plot function to plot the sine wave]

xticks ([0 : ten : 50])
[Using the xticks function to set the ticks for the x-axis]

Input:

Matlab xticks 5

Output:

to plot a sine wave

Equally nosotros can run into in the output, we have obtained ticks of our choice by passing a range as an argument to the xticks part.

Conclusion

The xticks part is used in Matlab to assign tick values to the ten-axis. The xticklabels function can exist used along with the xticks function to label the ticks assigned. Both a range and a ready of values tin be passed as an argument to the xticks role.

Recommended Articles

This is a guide to Matlab xticks. Hither nosotros hash out the introduction and the examples of the Matlab xticks for better understanding. Yous may also take a look at the post-obit manufactures to larn more than –

  1. What is Matlab?
  2. Matlab limit
  3. Plot graph Matlab
  4. Absolute Value Matlab

How To Set Step Size In Matlab Plot,

Source: https://www.educba.com/matlab-xticks/

Posted by: treatsmandertne.blogspot.com

0 Response to "How To Set Step Size In Matlab Plot"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel