-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathx_to_norm.m
51 lines (40 loc) · 1.97 KB
/
x_to_norm.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
function [x_norm] = x_to_norm_v2(x_begin,x_end)
if nargin ~= 2
error('Wrong number of input arguments.')
end
h_axes = get(gcf,'CurrentAxes'); %get axes handle
axesoffsets = get(h_axes,'Position');
x_axislimits = get(gca, 'xlim'); %get axes extremeties.
x_dir = get(gca,'xdir');
x_scale = get(gca,'xscale');
%get axes length
x_axislength_lin = abs(x_axislimits(2) - x_axislimits(1));
if strcmp(x_dir,'normal')
if strcmp(x_scale,'log')
x_axislength_log = abs(log10(x_axislimits(2)) - log10(x_axislimits(1)));
x_begin_norm = axesoffsets(1)+axesoffsets(3)*abs(log10(x_begin)-log10(x_axislimits(1)))/(x_axislength_log);
x_end_norm = axesoffsets(1)+axesoffsets(3)*abs(log10(x_end)-log10(x_axislimits(1)))/(x_axislength_log);
x_norm = [x_begin_norm x_end_norm];
elseif strcmp(x_scale,'linear')
x_begin_norm = axesoffsets(1)+axesoffsets(3)*abs((x_begin-x_axislimits(1))/x_axislength_lin);
x_end_norm = axesoffsets(1)+axesoffsets(3)*abs((x_end-x_axislimits(1))/x_axislength_lin);
x_norm = [x_begin_norm x_end_norm];
else
error('use only lin or log in quotes for scale')
end
elseif strcmp(x_dir,'reverse')
if strcmp(x_scale,'log')
x_axislength_log = abs(log10(x_axislimits(2)) - log10(x_axislimits(1)));
x_begin_norm = axesoffsets(1)+axesoffsets(3)*abs(log10(x_axislimits(2))-log10(x_begin))/(x_axislength_log);
x_end_norm = axesoffsets(1)+axesoffsets(3)*abs(log10(x_axislimits(2))-log10(x_end))/(x_axislength_log);
x_norm = [x_begin_norm x_end_norm];
elseif strcmp(x_scale,'linear')
x_begin_norm = axesoffsets(1)+axesoffsets(3)*abs((x_axislimits(2)-x_begin)/x_axislength_lin);
x_end_norm = axesoffsets(1)+axesoffsets(3)*abs((x_axislimits(2)-x_end)/x_axislength_lin);
x_norm = [x_begin_norm x_end_norm];
else
error('use only lin or log in quotes for scale')
end
else
error('use only r or nr in quotes for reverse')
end