MATLAB: How can plot figure similar to the attached figure

plotstairs

how can i plot a figure similar to the one i attach to this request ?
i want to specify the "PART A", "PART B" and "PART C" with MATLAB software.
Thanks a lot.

Best Answer

Use this code:
x = [4, 4, 10, 10, 12, 12, 15, 15];
y = [0, 1, 1, 0, 0, 1, 1, 0]
plot(x, y, 'k-', 'LineWidth', 2);
xlim([0, 16]);
ylim([0, 1.5]);
grid on;
hold on;
fontSize = 14;
text(4.1, 1.1, 'PART A', 'FontName', 'Times New Roman', 'FontSize', fontSize);
text(6, 1.24, 'PART B', 'FontName', 'Times New Roman', 'FontSize', fontSize);
text(12.1, 1.1, 'PART C', 'FontName', 'Times New Roman', 'FontSize', fontSize);
orange = [247, 128, 29]/255
y1 = 1.03;
y2 = 1.18
line([4, 8], [y1, y1], 'Color', orange, 'LineWidth', 3);
line([6, 10], [y2, y2], 'Color', orange, 'LineWidth', 3);
line([12, 15], [y1, y1], 'Color', orange, 'LineWidth', 3);
To put the tiny vertical lines at the ends of the orange lines, simply use line() again.