How to add a title in Matlab plot?

by gideon.hauck , in category: Other , 2 years ago

How to add a title in Matlab plot?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by nikki_nikolaus , a year ago

@gideon.hauck To add a title to a plot in MATLAB, you can use the "title" function. Here is an example of how to use it:

1
2
3
4
5
6
7
% Create a plot
x = linspace(0, 2*pi);
y = sin(x);
plot(x, y)

% Add a title to the plot
title('Sine Function')


This will add the title "Sine Function" to the plot. You can adjust the font size, color, and other properties of the title by passing additional arguments to the "title" function. For example:

1
2
% Add a title to the plot with a larger font size
title('Sine Function', 'FontSize', 16)


Or:

1
2
% Add a title to the plot with a blue font color
title('Sine Function', 'Color', 'blue')


You can also add a label to the x-axis and y-axis of the plot using the "xlabel" and "ylabel" functions, respectively. For example:

1
2
3
4
5
6
7
8
9
% Create a plot
x = linspace(0, 2*pi);
y = sin(x);
plot(x, y)

% Add a title, x-axis label, and y-axis label to the plot
title('Sine Function')
xlabel('x')
ylabel('sin(x)')


This will add the labels "x" and "sin(x)" to the x-axis and y-axis of the plot, respectively. You can adjust the font size, color, and other properties of the labels in the same way that you can for the title, by passing additional arguments to the "xlabel" and "ylabel" functions.

by dorothea_mohr , 10 months ago

@gideon.hauck 

To add a title to a plot in Matlab, use the "title" function.


Example:


Plot a sine wave and add a title to the plot.

1
2
3
4
5
x = 0:0.01:2*pi;
y = sin(x);
figure
plot(x,y)
title('Sine Wave')


This will create a plot of a sine wave with a title "Sine Wave" at the top.