-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexamples.m
81 lines (63 loc) · 2.16 KB
/
examples.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
%% Setup
% This assumes that the working directory is preplot-postplot (but also
% works if it is src).
close all; clearvars; clc;
addpath('src')
%% Simple example.
preplot();
plot(1:10)
postplot();
%% With some customization.
colors = [0.15, 0.34, 0.43;
0.42, 0.76, 0.61];
[f, axs] = preplot(2, 1, 'sharex', 'all', 'interpreter', 'latex', ...
'colororder', colors);
x = linspace(0, 5, 1e5);
plot(axs(1), x, [sin(x); cos(x)])
plot(axs(2), x, [log10(x); log(x)])
ylabel(axs(1), '$\alpha$')
ylabel(axs(2), '$\beta$')
xlabel(axs(2), 'Time (s)')
postplot(f, 'Images/test.pdf', 'width', 5, 'figSizeUnits', 'inches', ...
'aspectRatio', 1.5, 'fontSize', 16, 'legendFontSize', 14, ...
'lineWidth', 3);
% We can also save the same plot twice in different sizes, for example when
% you want to use it in a presentation and a paper.
postplot(f, 'Images/test2.pdf', 'width', 10, 'figSizeUnits', 'inches', ...
'aspectRatio', 1.5, 'fontSize', 20, 'legendFontSize', 16, ...
'lineWidth', 5);
%% Control plots
% Plots from the control toolbox don't work together with TiledLayout and
% are difficult to customize, so this toolbox also provides custom control
% plotting commands.
[f, axs] = preplot(2, 2, 'sharex', 'all');
axBig = nexttile(2, [2,1]);
sys = tf(4, [1, 0.7, 4]);
mbode(sys, axs(1,1), axs(2,1))
mnyquist(sys, axBig, 'w', logspace(-1, 2, 1e3))
xlim(axBig, [-2, 2])
postplot(f, 'linewidth', 1, 'fontname', 'Times New Roman');
%% Logarithmic plot
% Does not work:
% f = preplot();
% loglog(1:10)
% DO:
preplot('YScale', 'log', 'XScale', 'log', 'interpreter', 'latex');
plot(1:10)
% Or:
preplot('initializeAxes', false, 'interpreter', 'latex');
ax = nexttile;
loglog(ax, 1:10)
%% Example plot for README.
colors = [0.15, 0.34, 0.43;
0.42, 0.76, 0.61];
[f, axs] = preplot(2, 1, 'colororder', colors, 'interpreter', 'latex', ...
'sharex', 'all');
sys1 = tf(4, [1, 0.7, 4]);
sys2 = tf([1, 0.1, 4], [1, 1, 4]);
mbode([sys1, sys2], axs(1,1), axs(2,1))
ylim(axs(1), [-40, 20])
postplot(f, 'Images/example.png', 'width', 10, ...
'figSizeUnits', 'centimeters', 'aspectRatio', 1.2, ...
'fontname', 'default', 'fontSize', 10, 'legendFontSize', 8, ...
'lineWidth', 2);