matrix for loop question
조회 수: 2 (최근 30일)
이전 댓글 표시
Suppose I have a matrix [1 2 3 5;1 3 4 5]. Each row represents a path and each column represents the nodes of that path. For example: for row 1 : 1-2-3-5 is a path with nodes 1, 2 ,3, 5(where one is the start node and 5 is the end node). I want to consider an arc and arcs following that arc. For example: I want to consider (1,2) and (2-3) and assign a cost to it. I wrote a code but its showing an error. please help!
for kkp = 1:size(R{ip},1) % R{ip} is my path matrix
for jjp = 1:size(R{ip},2)-1
for iip = 1:size (R{ip,2} -2)
up = R{ip}(kkp,jjp);
vp = R{ip}(kkp,jjp+1);
wp = R{ip}(kkp,jjp+2);
cost1 = wt(up,vp); %wt(i,j) is a cost matrix that i already inputed.
cost 2 = wt(vp,wp);
end
end
end
댓글 수: 0
채택된 답변
Eugene
2013년 5월 30일
You're indexing 'R' as a 1-D cell array at the start however in the third line you start indexing the 2nd dimension.
for iip = 1:size (R{ip,2} -2)
I think you meant
for iip = 1:size(R{ip},2) - 2
And a typo at (no space between 'cost' and '2'):
cost 2 = wt(vp,wp);
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!