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