how to give multiple xlines labels in matlab

To give multiple x-axis labels in Matlab, you can use xticklabels function. For example:

main.m
% Creating a sample plot with multiple x-lines
x = 1:10;
y = rand(10,2);
plot(x, y)
hold on;
xline(3.5, '--r');
xline(8, '--g');

% Giving labels to each x-line
xticks([3.5, 8])
xticklabels({'label1', 'label2'})
212 chars
12 lines

In this example, xline is used to plot two vertical lines at x=3.5 and x=8. xticks function is used to set these lines as the tick marks and xticklabels function is used to give labels to each x-line.

You can modify the labels and x-lines positions according to your needs.

related categories

gistlibby LogSnag