function [dataWithAtt, totalAttNum] = CombineDataWithAttributes(data, attributes, attUpperRange, attWeight)

totalAttNum = sum(attUpperRange);
sizeWithAtt = totalAttNum + size(data,1);
dataWithAtt = zeros(sizeWithAtt, sizeWithAtt);
dataWithAtt(totalAttNum+1:end,totalAttNum+1:end) = data;

numAttTypes = size(attUpperRange,2);
attOffsets = zeros(numAttTypes);
nodeOffset = totalAttNum;

if (numAttTypes>1)
    for i=2:numAttTypes
        attOffsets(i) = attOffsets(i-1)+attUpperRange(i-1);
    end
end

dataLines = size(data,1);
attLines = size(attributes,1);
if (attLines ~= dataLines)
        fprintf('CombineDataWithAttributes - Invalid data sizes: data %d, attributes %d\n',dataLines,attLines);
end

for line=1:dataLines
    for att=1:numAttTypes
        value = attributes(line,att);
        if value > 0
            dataWithAtt(nodeOffset+line,attOffsets(att)+value)=attWeight;
            dataWithAtt(attOffsets(att)+value,nodeOffset+line)=attWeight;
        end
    end
end
    
dataWithAtt = sparse(dataWithAtt);

