I want the code to make this. I am not able to make this.
I have one vector and one matrix..
Facility_units=[4 2 3 1]
total=4+2+3+1=10
matrix D=
[0 4 2 4 ;
4 0 1 3 ;
2 1 0 2 ;
4 3 2 0]
D is symmetric matrix in which diagonal element is 0 and upper triangle is similar to lower triangle.
I want the output in this form e.g.
output= 10*10 matrix i.e. total*total
[
0 0 0 0 4 4 2 2 2 4 ;
0 0 0 0 4 4 2 2 2 4 ;
0 0 0 0 4 4 2 2 2 4 ;
0 0 0 0 4 4 2 2 2 4 ;
4 4 4 4 0 0 1 1 1 3 ;
4 4 4 4 0 0 1 1 1 3 ;
2 2 2 2 1 1 0 0 0 2 ;
2 2 2 2 1 1 0 0 0 2 ;
2 2 2 2 1 1 0 0 0 2 ;
4 4 4 4 3 3 2 2 2 0 ]
output matrix is 10-by-10 in which elements are repeated according to vector Facility_units.
1st facility having 4 units, 2nd has 2 units, 3rd has 3 units and 4th has 1 unit.
D is the matrix shows the distance between each facility. e.g. distance between facility 1 and 2 is 4, between 1 and 3 is 2 and between 1 and 4 is 4. according to that matrix D (i.e. distance matrix) is made.
Now i want the output that shows the distance between each unit of the facility with any other units. e.g. units of same facility having distance 0. 1st facility have 4 units that is why in output matrix 1:4 row by 1:4 column is 0.
than distance of units of facility 2 with facility 1 is 2.
ss(1)=0;
for q=2:number+1
ss(q)=ss(q-1)+facility_units(q-1);
end
ss
dist=zeros(tu,tu);
for i=1:number
for j=1:number
if di(i,j)~=0 && i~=j && i<j>
for l=ss(j-1)+1:ss(j)
for m=ss(j)+1:ss(j+1)
dist(l,m)=di(i,j);
end
end
for l=ss(j)+1:ss(j+1)
for m=ss(j-1)+1:ss(j)
dist(l,m)=di(i,j);
end
end
end
end
end
dist