Newer
Older
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
classdef RGrid < handle
properties
Cells = [];
Grid1 = [];
Grid2 = [];
end
methods
%% RGrid
% constructor method
% inputs:
% g1:Grid - reference to top grid
% g2:Grid - reference to left grid.
% outputs;
% n:RGrid - Created RGrid
function n = RGrid(g1, g2)
n.Grid1 = g1;
n.Grid2 = g2;
end
%% new_RCell
% creates a new Cell in the current RGrid
% inputs:
% obj:RGrid - current RGrid object
% cell1:Cell - reference to condition cell in top grid
% cell2:Cell - reference to condition cell in left grid
% outputs;
% none
function [] = new_RCell(obj,cell1,cell2)
cell = RCell;
cell.Cell1 = cell1;
cell.Cell2 = cell2;
obj.Cells = [obj.Cells cell];
end
%% search
% determine wheter a results cell exists for a pair of condition
% cells.
% inputs:
% obj:RGrid - reference to current RGrid
% cell1:Cell - reference to condition cell in top grid.
% cell2:Cell - reference to condition cell in left grid.
% outputs;
% cell:boolean - 1 if cell is found, 0 if cell is not found
function cell = search(obj,cell1,cell2)
cell = 0
for i=1:size(obj.Cells,2)
if (obj.Cells(i).Cell1 == cell1 && obj.Cells(i).Cell2 == cell2);
cell = 1;
end
end
end
%% search_return
% determine where a results cell exists for a pair of condition
% cells and returns the cell itself.
% inputs:
% obj:RGrid - reference to current RGrid
% cell1:Cell - reference to condition cell in top grid.
% cell2:Cell - reference to condition cell in left grid.
% outputs;
% cell:RCell - if found returns reference to cell, if not returns
% empty
function cell = search_return(obj,cell1,cell2)
cell = [];
for i=1:size(obj.Cells,2)
if (obj.Cells(i).Cell1 == cell1 && obj.Cells(i).Cell2 == cell2);
cell = obj.Cells(i);
end
end
end
%% refresh
% calls the setup function, might add furthur functionality in
% the future to this function
% inputs:
% obj:RGrid - reference to current RGrid
% outputs;
% none
function [] = refresh(obj)
obj.setup(obj.Grid1,obj.Grid2);
end
%% delete_g2s
% function will delete all the cells that reference an inputed
% condition cell as their Cell2.
% inputs:
% obj:RGrid - reference to current RGrid
% cell:Cell - reference to cell being deleted
% outputs;
% none
function [] = delete_g2s(obj,cell)
deleted = [];
% loop through all the cells, if we find any Rcell with cell as
% its Cell2 then add the index to the array, if we were to
% delete the cell right away the array size would decrease and
% we would get out of bounds issues.
for i=1:size(obj.Cells,2)
if (obj.Cells(i).Cell2 == cell)
deleted = [deleted i];
end
end
if(~isempty(deleted))
delete(obj.Cells(deleted).result);
obj.Cells(deleted) = [];
end
end
%% delete_g1s
% Same as delete_g2s but we are now deleting RCell with a
% reference to the inputed cell in their Cell1
% inputs:
% obj:RGrid - reference to current RGrid
% cell:Cell - reference to cell being deleted
% outputs;
% none
function [] = delete_g1s(obj,cell)
deleted = [];
for i=1:size(obj.Cells,2)
if (obj.Cells(i).Cell1 == cell)
deleted = [deleted i];
end
end
if(~isempty(deleted))
delete(obj.Cells(deleted).result);
obj.Cells(deleted) = [];
end
end
%% setup
% this function will loop through all the cells in both the left
% grid and the top grid, once we reach a leaf cell for both
% grids, if there does not exist an RCell in the RGrid for both
% these leaf cells then we need to create one.
% inputs:
% obj:RGrid - reference to current RGrid
% g1:Grid - reference to the top grid
% g2:Grid - reference to the left grid.
% outputs;
%
function [] = setup(obj,g1,g2)
for i=1:size(g2.cells,2)
if (~isempty(g2.cells(i).subgrid))
obj.setup(g1,g2.cells(i).subgrid);
else
for j=1:size(g1.cells,2)
if(~isempty(g1.cells(j).subgrid))
obj.setup(g1.cells(j).subgrid,g2);
else
if (obj.search(g1.cells(j),g2.cells(i)) == 0)
rcell = RCell(g1.cells(j),g2.cells(i));
obj.Cells = [obj.Cells rcell];
end
end
end
end
end
end
end
end