function [binary,FccSize] = WeightedEdgesGraph(r,c,p,sparse,dirname)
%Create a Graph on a r (row) by c (col) grid with weighted edges between vertices.
%prob refers to the probability of each individual edge existing.
%saveSadjfinal is the output matrix of sparse adjacency matrices with
%varying edges.
%
% INPUTS
%      r = Number of horizontal rows
%      c = Number of vertical columns
%      p = Probability that a random pair of adjacent vertices is connected
% sparse = r x c size lattice which details the pairs of adjacent indices 
%          that are connected
%
% OUTPUTS
% saveSadjfinal = 
%       FccSize =  
%================================================================

%Assign each value in sparse a random value between 0 and 1
vindex = find(sparse);
sparse(vindex) = rand(size(vindex)); 

%Test to see if pseudorandom non-zero element is greater or less than "p" and
%assign sparse 0 or 1;
if sparse < (1-p); %1-p because wgPlot plots all edges, and removes those with zero.
    sparse = 0;

else sparse >= (1-p); %Something isn't quite right here, but it works correctly.
    sparse = 1;
    sparse = ans;
end

%Alternatively, the above if-else statement can be simply represented as 
%sparse = sparse >= (1-p)

binary = sparse;

%Plots graph and saves
%[hE,hV] = wgPlot(sparse,coord,'edgeWidth',2) %Prints plots
%fname = (strcat(dirname,'/result',num2str(runtimes)));
%saveas([hE,hV],fname,'fig'); 

%% Adjacency Matrix Stuff below. Not cleaned up
%cadj = full 'changed' derivation from sparse
%cadj = full(sparse);
%cadj = cadj + cadj.';

% find 'l'ength and the size (number) of connected components ('cc')
%[l, ccSize] = graph_conn_comp(cadj);

%If there exists any value in a column c, ignore. If there exists no
%value in that column, subtract one (as that coordinate is not
%connected to anything --> "singular" connected component)
%for cycle = 1:(r*c)
%   if any(cadj(:,cycle),1) > 0
%   else
%       ccSize = ccSize - 1;
%   end
%end

%FccSize=ccSize;
FccSize = [];

%end

%toc

%disp('done')

end
