-
Notifications
You must be signed in to change notification settings - Fork 0
/
logy2raw.m
44 lines (38 loc) · 1.23 KB
/
logy2raw.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
function logy2raw(base, precision)
% logy2raw(base, precision)
%
% Converts Y-axis labels from log to raw values.
%
% Inputs:
% base Base of log transform (default: e)
% precision Number of decimal places (default: 2)
%
% Example:
% x = linspace(-3,0,11);
% plot(log(x), log(x.^2));
% logx2raw();
% logy2raw(); % should be tolerant to multiple calls
%
% Note:
% - See also: logx2raw.m
% 11/17/96 gmb wrote it.
% 6/6/96 gmb added precision argument
% 01/30/02 gmb updated it to use cell arrays, and to use original
% xtick values instead of converting labels. This way,
% multiple calls to this function doesn't keep converting
% the axis.
% Edited by Kelly Chang - February 18, 2017
%% Input Control
if ~exist('base', 'var')
base = exp(1);
end
if ~exist('precision', 'var')
precision = 2;
end
%% Calculate Log x-axis Labels
precision = sprintf('%%%2.1ff', precision*1.1);
origYTick = get(gca, 'YTick'); % log y-axis labels (raw)
newYTick = base.^(origYTick); % convert to raw
newYLabel = arrayfun(@(x) sprintf(precision,x), newYTick, ...
'UniformOutput', false); % write new y-axis labels
set(gca, 'YTickLabel', newYLabel); % set y-axis labels of current graph