-
Notifications
You must be signed in to change notification settings - Fork 3
/
rimcheck.m
73 lines (70 loc) · 2.46 KB
/
rimcheck.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
function [A,B]=rimcheck(A,B,rim,M,xver,sev)
% [A,B]=RIMCHECK(A,B,rim,M,xver,sev)
%
% Uses the output of PUZZLE to check the rims of matrices, and trim them
%
% INPUT:
%
% A,B Two matrices, not necessarily the same size, some overlap
% rim The rim size of possible overlap
% M The PUZZLE match code - only 8, 4, 2 and 1 get trimmed
% xver 1 issue warnings relevant for particular alignment situations
% only in some of the cases relevant to TINITALY, but also
% triggers an error rather than a warning when the time comes
% 0 do not issue any warnings [default]
% sev 0 produces WARNING upon failure [default]
% 1 produces ERROR upon failure
% 2 invokes KEYBOARD upon failure
%
% OUTPUT:
%
% A,B The two matrices where one was trimmed to avoid the overlap
%
% Last modified by fjsimons-at-alum.mit.edu, 12/16/2019
% Default is to not check
defval('xver',0)
% Default is to issue warnings (and not errors)
defval('sev',0)
% In TINITALH, higher numbers are typically to the right or up... but I
% have preferred to spell out the cases where the individual lines are
% least different!
switch M
case 8
% [D1 D2] is the match with overlap
% Just use the case below with switched inputs
[B,A]=rimcheck(B,A,rim,4,xver);
% The next line was in error but didn't matter
%[A,B]=deal(B,A);
case 4
% [D2 D1] is the match with overlap
if size(B,1)<size(A,1)
% B has a smaller ROW size and is to the LEFT of A
if xver==1; diferm(B(:,end-rim+1:end),A(1:size(B,1),1:rim),[],sev); end
% Now B gets trimmed on the right
B=B(:,1:end-rim,:);
else
% B has a larger ROW size and is to the LEFT of A
if xver==1; diferm(B(1:size(A,1),end-rim+1:end),A(:,1:rim),[],sev); end
% Now A gets trimmed from the left
A=A(:,rim+1:end);
end
case 2
% [D1 ; D2] is the match with overlap
% Just use the case below with switched inputs
[B,A]=rimcheck(B,A,rim,1,xver);
% The next line was in error but didn't matter
%[A,B]=deal(B,A);
case 1
% [D2 ; D1] is the match with overlap
if size(B,2)<size(A,2)
% B has a smaller COLUMN size and is on TOP of A
if xver==1; diferm(B(end-rim+1:end,:),A(1:rim,1:size(B,2)),[],sev); end
% Now B gets trimmed at the bottom
B=B(1:end-rim,:);
else
% B has a larger COLUMN size and is on TOP of A
if xver==1; diferm(B(end-rim+1:end,1:size(A,2)),A(1:rim,:),[],sev); end
% Now A gets trimmed from the top
A=A(rim+1:end,:);
end
end