3 %> @brief Draws loadings curves with many options
5 %> @param x [nf] x-axis values.
6 %> @param L [nf][number_of_loadings] loadings matrix.
7 %> @param x_hint =[]. [nf] x-axis values. If not passed or empty, uses @a x
if @a hint is passed.
8 %> @param hint [nf]
"hint" curve that helps the reading of the loadings. If not passed or empty, no hint curve is drawn.
9 %> @param legends =[] One legend per loadings curve. If not passed, no legend is drawn.
10 %> @param flag_abs =0 Whether to take the absolute value of the loadings matrix.
11 %> @param peakd =[] Peak Detector
object.
12 %> @param flag_trace_minalt =0 Whether to draw the threshold line. Only works
if @a threshold is passed.
13 %> @param flag_draw_peaks =0 Whether to mark the detected peaks in the figure.
14 %> @param flag_print_peaks =0 Whether to print detected peaks on the command line window.
15 %> @param flag_histogram =0 Whether to plot line or histogram.
16 %> @param flag_envelope =0 If
true, will detect all peaks,
do spline interpolation and plot
this instead
17 %> @param colors =[1, 2, 3...]. See the possibilities:
18 %> @arg [] : Defaults to sequential color indexes [1, 2, 3...]
19 %> @arg 1-D vector : interpreted
as color indexes (arguments to @ref
find_color.m)
20 %> @arg cell : interpreted
as a cell of colours
21 function draw_loadings(x, L, x_hint, hint, legends, flag_abs, peakd, flag_trace_minalt, flag_draw_peaks, flag_print_peaks, flag_histogram, flag_envelope, colors)
23 if ~exist('x_hint', 'var') || isempty(x_hint)
26 if ~exist('hint', 'var') || isempty(hint)
29 if ~exist('legends', 'var')
32 if ~exist('peakd', 'var')
35 if ~exist('flag_trace_minalt', 'var') || isempty(flag_trace_minalt)
36 flag_trace_minalt = 0;
38 if ~exist('flag_abs', 'var') || isempty(flag_abs)
41 if ~exist('flag_draw_peaks', 'var') || isempty(flag_draw_peaks)
44 if ~exist('flag_print_peaks', 'var') || isempty(flag_print_peaks)
47 if ~exist('flag_histogram', 'var') || isempty(flag_histogram)
50 if ~exist('flag_envelope', 'var') || isempty(flag_envelope)
53 if ~exist('colors', 'var') || isempty(colors)
54 colors = 1:size(L, 2);
61 colors_eff = arrayfun(@
find_color, colors, 'UniformOutput', 0);
65 % Bonus: checks whether L is a row vector
68 L = L'; % Daring guess;
70 irerror('Loadings vector has incorrect size!');
75 % Used for the calculations
78 Ltemp = Ltemp(Ltemp ~= Inf);
79 Lcalc(Lcalc == Inf) = max(Ltemp(:)); % Inf protection
87 ymin = min(min(Lcalc));
90 ymax = max(max(Lcalc));
91 ymaxabs = max(max(abs(Lcalc)));
92 flag_bother_peaks = ~isempty(peakd) && (flag_print_peaks || flag_draw_peaks);
101 ipe = opd.use(x, L(:, i));
102 % Lenv(:, i) = spline(x(ipe), L(ipe, i), x);
103 Lenv(:, i) = interp1(x(ipe), L(ipe, i), x);
122 % Makes a fader color
123 color1 = rgb(colors_eff{i});
124 color1 = color1*0.3+max(color1)*0.7;
126 color2 = colors_eff{i};
129 color1 = colors_eff{i};
139 for j = 1:1 %numel(y)
140 hh = stem(x, y, 'Color', color1, 'LineWidth', 2*width1, 'Marker', 'none');
141 if ~flag_envelope && j == 1
149 handles(i) = plot(x, Lenv(:, i)', 'Color', color2, 'LineWidth', width2);
154 % Peak detectors know how to deal with Inf, need not use Lcalc
156 peakd = peakd.boot(x, y);
157 idxs_peaks = peakd.use([], y);
165 s = sprintf('for ''%s''', legends{i});
167 s = sprintf(
'%d', i);
169 fprintf(
'---------------- Peaks %s -----------------\n', s);
173 % Plots
"minimum altitude" line
185 hl = legend(handles, legends);
191 ylabel('Coefficient (a.u.)');
209 ylim([y0, y2+yspan*0.025]);
function draw_peaks(in x, in y, in indexes, in flag_text, in color, in marker, in markersize)
function find_color(in i)
function print_peaks(in x, in idxs_peaks)
function draw_hint_curve(in x, in y, in color)
function draw_threshold_line(in x, in y, in width, in color)
function plot_curve_pieces(in x, in y, in varargin)
function draw_loadings(in x, in L, in x_hint, in hint, in legends, in flag_abs, in peakd, in flag_trace_minalt, in flag_draw_peaks, in flag_print_peaks, in flag_histogram, in flag_envelope, in colors)
Analysis Session (AS) base class.
function draw_zero_line(in x, in linewidth)