-
Notifications
You must be signed in to change notification settings - Fork 25
/
get_target_diagram_axes.m
131 lines (118 loc) · 3.31 KB
/
get_target_diagram_axes.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
function [axes,option] = get_target_diagram_axes(x,y,option)
%GET_TARGET_DIAGRAM_AXES Get axes value for target_diagram function.
%
% [AXES,OPTION] = GET_TARGET_DIAGRAM_AXES(X,Y,OPTION)
% Determines the axes information for a target diagram given the axis
% values (X,Y) and the options in the data structure OPTION returned by
% the GET_TARGET_DIAGRAM_OPTIONS function.
%
% INPUTS:
% x : values for x-axis
% y : values for y-axis
% option : data structure containing option values. (Refer to
% GET_TARGET_DIAGRAM_OPTIONS function for more information.)
%
% OUTPUTS:
% axes : data structure containing axes information for target diagram
% axes.xtick : x-values at which to place tick marks
% axes.ytick : y-values at which to place tick marks
% axes.xlabel : labels for xtick values
% axes.ylabel : labels for ytick values
% option : data structure containing updated option values
% save nxticks and nyticks between function calls
persistent nxticks_old nyticks_old
% Specify max/min for axes
if isfield(option, 'axismax')
foundmax = 1;
else
foundmax = 0;
end
if foundmax == 0
% Axis limit not specified
maxx = max(abs(x(:)));
maxy = max(abs(y(:)));
else
% Axis limit is specified
maxx = option.axismax;
maxy = option.axismax;
end
% Determine default number of tick marks
hhh = plot([-maxx -maxx maxx maxx],[-maxy maxy maxy -maxy]);
v = [get(gca,'xlim') get(gca,'ylim')];
get(gca,'xtick');
ntest = sum(get(gca,'xtick')>0);
if ntest > 0
nxticks = sum(get(gca,'xtick')>0); nyticks = sum(get(gca,'ytick')>0);
nxticks_old = nxticks; nyticks_old = nyticks;
else
nxticks = nxticks_old; nyticks = nyticks_old;
end
delete(hhh);
% Set default tick increment and maximum axis values
if foundmax == 0;
maxx = v(2);
maxy = v(4);
option.axismax = max(maxx, maxy);
end
% Check if equal axes requested
if isfield(option,'equalAxes') && strcmp(option.equalAxes,'on')
if maxx > maxy
maxy = maxx;
nyticks = nxticks;
else
maxx = maxy;
nxticks = nyticks;
end
end
minx = -maxx;
miny = -maxy;
% Determine tick values
if isfield(option, 'ticks') && length(option.ticks) > 0
xtick = option.ticks;
ytick = option.ticks;
else
tincx = maxx/nxticks;
tincy = maxy/nyticks;
xtick = minx:tincx:maxx;
ytick = miny:tincy:maxy;
end
% Assign tick label positions
if ~isfield(option,'xticklabelpos')
option.xticklabelpos = xtick;
end
if ~isfield(option,'yticklabelpos')
option.yticklabelpos = ytick;
end
% Set tick labels using provided tick label positions
xlabel = cell(1,length(xtick));
ylabel = cell(1,length(ytick));
% Set x tick labels
for i=1:length(xtick)
index = find(xtick(i) == option.xticklabelpos);
if length(index) > 0
xlabel{i} = num2str(xtick(i));
else
xlabel{i} = '';
end
end
% Set tick labels at 0 to blank
index = find(xtick == 0);
xlabel{index} = '';
% Set y tick labels
for i=1:length(ytick)
index = find(ytick(i) == option.yticklabelpos);
if length(index) > 0
ylabel{i} = num2str(ytick(i));
else
ylabel{i} = '';
end
end
% Set tick labels at 0 to blank
index = find(ytick == 0);
ylabel{index} = '';
% Store output variables in data structure
axes.xtick = xtick;
axes.ytick = ytick;
axes.xlabel = xlabel;
axes.ylabel = ylabel;
end % function get_target_diagram_axes