-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathneg_loglog.m
135 lines (122 loc) · 3.58 KB
/
neg_loglog.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
132
133
134
135
function h = neg_loglog(x,y,h, varargin)
% h = neg_loglog(x,y,h, varargin)
%
% neg_loglog.m is part of the CR1Dmod forward modeling package, and contains
% the code used to plot data-sets with negative values on a log-log scale.
% For example, the CR-effect in TEM calculations may cause the response in
% certain time ranges to become negative. The negative data are plotted
% as positive, but with a different line type.
%
% Inputs:
% x: Vector of x values
% y: Vector of y values
% h: Uses the figure with handle h for plotting
% varargin: Additional arguments are passed directly to loglog
%
% Output:
% h: handle to the plot figure.
%
% Written by:
% Thomas Ingeman-Nielsen
% The Arctic Technology Center, BYG
% Technical University of Denmark
% Email: [email protected]
if ((isappdata(0,'compiled') && getappdata(0,'compiled')) || exist('h','var')) && ...
ishandle(h)
figure(h);
else
h = figure;
end
if nargin > 3
plotProp = varargin(1:end);
else
plotProp = {};
end
if all(isreal(y))
% in case of real input, make 1 plot
% define segments where all data have the same sign
segment = 1;
a = sign(y(1));
if a==0, a=1; end;
for k = 2:length(y)
a2 = sign(y(k));
if a2==0, a2=1; end;
if a2~=a
segment = [segment k];
end
a = a2;
end
segment = [segment, length(y)+1];
% determine the plot properties
if sign(y(segment(1)))==1 || sign(y(segment(1)))==0
color = '-ob-or';
else
color = '-or-ob';
end
% Do the plotting
for k = 1:length(segment)-1
loglog(x(segment(k):segment(k+1)-1),y(segment(k):segment(k+1)-1),...
color(1:3), plotProp{:});
hold on;
color = color([4 5 6 1 2 3]);
y = -y;
end
else
% in case of complex input, make 2 plots
% Treat the real data first
% define segments where all data have the same sign
subplot(2,1,1);
segment = 1;
a = sign(real(y(1)));
if a==0, a=1; end;
for k = 2:length(y)
a2 = sign(real(y(k)));
if a2==0, a2=1; end;
if a2~=a
segment = [segment k];
end
a = a2;
end
segment = [segment, length(y)+1];
% determine the plot properties
if sign(real(y(segment(1))))==1 || sign(real(y(segment(1))))==0
color = '-ob-or';
else
color = '-or-ob';
end
% Do the plotting
for k = 1:length(segment)-1
loglog(x(segment(k):segment(k+1)-1),abs(real(y(segment(k):segment(k+1)-1)),...
color(1:3), plotProp{:}));
hold on;
color = color([4 5 6 1 2 3]);
end
% Now treat the imaginary part
% define segments where all data have the same sign
subplot(2,1,2);
segment = 1;
a = sign(imag(y(1)));
if a==0, a=1; end;
for k = 2:length(y)
a2 = sign(imag(y(k)));
if a2==0, a2=1; end;
if a2~=a
segment = [segment k];
end
a = a2;
end
segment = [segment, length(y)];
% determine the plot properties
if sign(imag(y(segment(1))))==1 || sign(imag(y(segment(1))))==0
color = '-ob-or';
else
color = '-or-ob';
end
% Do the plotting
for k = 1:length(segment)-1
loglog(x(segment(k):segment(k+1)-1),abs(imag(y(segment(k):segment(k+1)-1)),...
color(1:3), plotProp{:}));
hold on;
color = color([4 5 6 1 2 3]);
end
end