%% Returns a model grid with alternating checkerboard pattern of values +1 and -1 %% ====================================================================================== %% %% Parameters: %% model - structure describing the 2D rectangular model. %% inc_rows - increment of the pattern in rows (depth) %% inc_cols - increment of the pattern in columns (horizontal distance) %% Returns: %% pattern - grid containing values +1 or -1 function pattern = checkerboard(model,inc_rows,inc_cols) pattern = ones(model.nz,model.nx); nr = size(pattern,1); nc = size(pattern,2); % change sign, first in alternating groups of rows, % and then in alternating groups of columns for i=1:2*inc_rows:nr ind = i:min( [(i+inc_rows-1), nr]); % range of rows to flip sign pattern(ind,:) = -pattern(ind,:); end for i=1:2*inc_cols:nc ind = i:min( [(i+inc_cols-1), nc]); % range of columns to flip sign pattern(:,ind) = -pattern(:,ind); end end