2% MERGEWEIGHTS a function to add weights at similar nodes to avoid double
3% sums
4%
5% Inputs:
6% A: some matrix A with some repeated elements
7% w: weights corresponding to each element of matrix A
8% Outputs:
9% v: the collapsed matrix A with no repeated elements
10% wv: the sum of weights of repeated elements of A. Each such sum
11% corresponds to the unique value of the element saved in v.
13[m,n] = size(A);
14v = unique(A); % create a vector with unique A elements
15wv = zeros(length(v),1);
16for i = 1:m
17 for j = 1:n
18 idx = find(v == A(i,j));
19 wv(idx) = wv(idx) + w(i,j);
20 end
21end
23wv_out = zeros(Wth,1);
24wv_out(v(1):(v(1) + length(v)-1)) = wv;
26end