function [meandering_grid, X_edges, Y_edges] = make_grid(river, grid_width, grid_height) run_time = numel(river); disp_progress = 100; %shift = 100; for ii = 1:numel(river)-1 maxima_X(ii) = max(river(ii).Xcl); minima_X(ii) = min(river(ii).Xcl(river(ii).Xcl>0)); maxima_Y(ii) = max(river(ii).Ycl); minima_Y(ii) = min(river(ii).Ycl); end X_lim = max(maxima_X) ; % + shift X_min = min(minima_X) ; Y_lim = max(maxima_Y); Y_min = min(minima_Y); grid_length = round(run_time); meandering_grid(grid_length).map = []; Y_range = Y_lim + abs(Y_min); X_range = X_lim + abs(X_min); for ii = 1:run_time tic if ii == 1 structure = 1; else structure = structure+1; end %for pp = 1:grid_length meandering_grid(structure).map = zeros(grid_height,grid_width); %end [r, c] = find(river(ii).Xcl > 0); X = river(ii).Xcl(r); Y = river(ii).Ycl(r); % interprets points in the channel centerline into 350 evenly spaced % points %[XY] = interparc(number_interp_points,X,Y,'spline'); % Holy shit this %takes forever to run -> interpolate from curvature is a bad ida for %this %meandering_grid(ii).X = XY(:,1); % Shift my X and Y values into the positive %X = XY(:,1) + 10; %Y = XY(:,2) + Y_lim; %X(X<0) = 0; %Y = Y + Y_min; % discretzie the Y values into bins. % I use the bin values to plot on my grid %X_stepping = (X_lim+100)/grid_width; X_stepping = X_range/grid_width; %Y_stepping = (Y_lim+100)/grid_height; Y_stepping = Y_range/grid_height; %X_edges = 0:X_stepping:X_lim+100; X_edges = X_min:X_stepping:X_lim; X_edges(end) = X_lim; %Y_edges = (Y_lim-Y_min):Y_stepping:(Y_lim*2);% Y_edges = 0:Y_stepping:(Y_lim*2); Y_edges = Y_min:Y_stepping:Y_lim; B_X = discretize(X,X_edges); B_Y = discretize(Y,Y_edges); %meandering_grid(ii).Y = B; %% Set up grid length_BX = length(B_X); for pp = 1:length_BX-1 width = B_X(pp); height = B_Y(pp); meandering_grid(structure).map(height,width) = 1; end % print the progress if rem(ii,disp_progress) == 0 pct = ii/run_time*100; disp([num2str(pct),'% finished']); toc tic end end end