I have written the following code which seems to work.
sparse(A);
[i,j,s]=find(sparse(A));
SPRS_Mat=[i,j,s];
Links=SPRS_Mat(:,1:2);
link_sum_flow=[];
for ll=1:size(Links,1)
this_link=Links(ll,:);
Link_flow=[];
linkFlow=[];
for spr=1:size(pathMat,1)
for spcol=1:size(pathMat,2)
this_path=pathMat{spr,spcol}; % for every path of pathMat:
path_or=this_path(1); % find the Origin
path_dest=this_path(end); % find the Destination
path_OD=OD(path_or,path_dest); % find the corresponding OD
% Check if this link belongs to this path
[tf,loc] = ismember(this_link,this_path);
if (tf(1)==1 && tf(2)==1 && abs(loc(1)-loc(2))==1)
% Add the OD flow on this link
linkFlow(spcol)=path_OD;
else
linkFlow(spcol)=0;
end
end
Link_flow(spr,:)=linkFlow; % matrix with all flows of thislink
end
Link_flow;
link_sum_flow(ll)=sum(sum(Link_flow,1));
end
link_sum_flow; % The vector with the flows for each link
LinkFlowMat=[SPRS_Mat,link_sum_flow'];
But I would appreciate any tips for more efficient implementation since my real networks are much bigger than this example.
Thanks,
Iro