IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
make_box.m
Go to the documentation of this file.
1 %>@ingroup graphicsapi
2 %>@file
3 %>@brief Makes box around gca using xlim and ylim
4 function make_box()
5 
6 v_xlim = get(gca, 'xlim');
7 v_ylim = get(gca, 'ylim');
8 % plot(v_xlim([1, 2, 2, 1, 1]), v_ylim([1, 1, 2, 2, 1]), 'LineWidth', scaled(2), 'Color', [0, 0, 0]);
9 
10 xs = diff(v_xlim);
11 ys = diff(v_ylim);
12 
13 p = [v_xlim(1)+xs*.000001, v_ylim(1)+ys*.000001, xs*.999998, ys*.999998];
14 
15 
16 hh = guidata(gcf);
17 if isfield(hh, 'boxhandles')
18  idx = find(hh.boxaxes == gca());
19  if ~isempty(idx)
20  h = hh.boxhandles(idx);
21  flag_new = 0;
22  try
23  set(h, 'Position', p, 'LineWidth', scaled(2), 'EdgeColor', [0, 0, 0], 'FaceColor', 'none', 'Clipping', 'off');
24  catch ME %#ok<NASGU>
25  % Silent exception
26  flag_new = 1;
27  end;
28  else
29  flag_new = 1;
30  end;
31 else
32  flag_new = 1;
33 end;
34 
35 if flag_new
36  if ~isfield(hh, 'boxhandles')
37  hh.boxaxes = [];
38  hh.boxhandles = [];
39  end;
40  r = rectangle('Position', p, 'LineWidth', scaled(2), 'EdgeColor', [0, 0, 0], 'FaceColor', 'none', 'Clipping', 'off');
41  hh.boxaxes(end+1) = gca();
42  hh.boxhandles(end+1) = r;
43  guidata(gcf, hh);
44 end;
45 
function make_box()
function scaled(in i)