function Kgg=AddElemMatrix(Ke,Kgg)
%ADDELEMMATRIX - adds a particular stiffness matrix to the global system matrix of the model
%
%   Usage:
%      Kgg=AddElemMatrix(Ke,Kgg)

%Non optimized code
if Ke.nrows~=0,
	for i=1:Ke.nrows,
		for j=1:Ke.nrows,
			Kgg(Ke.row_indices(i),Ke.row_indices(j))=Kgg(Ke.row_indices(i),Ke.row_indices(j))+Ke.terms(i,j);
		end
	end
end

%Optimized code: 
%if Ke.nrows~=0,
%	Kgg(Ke.row_indices(1:Ke.nrows),Ke.row_indices(1:Ke.nrows))=Kgg(Ke.row_indices(1:Ke.nrows),Ke.row_indices(1:Ke.nrows))+Ke.terms(1:Ke.nrows,1:Ke.nrows);
%end
