フィルターのクリア

matrix for loop question

1 回表示 (過去 30 日間)
jana
jana 2013 年 5 月 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

採用された回答

Eugene
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);
  2 件のコメント
jana
jana 2013 年 5 月 30 日
I've made the correction but it is still showing an error. My cost2 outpput is coming as zero but that is not right.
my wt matrix is :
wt =[0 2 4 0;1 0 5 3;4 5 0 5;0 3 5 0];
so if for path 1-2-3-4 cost1 should be 2 and cost2 should be 5 (for 2-3) and 5 (for 3-4) .
jana
jana 2013 年 5 月 30 日
nevermind..I fixed it. Thanks.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEquivalent Baseband Simulation についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by