how to solve Ring topology?

조회 수: 11 (최근 30일)
Mudasir Ahmed
Mudasir Ahmed 2016년 1월 5일
답변: Guillaume 2016년 1월 5일
hi
i have two matrix, y contains the variable and d contains their solutions. Now first, i want to pair them in ring format (circle shape). as 5 elements are in y matrix which means 5 different pairs will be build containing total three variable, one is itself and other two are their adjacent.
y=[x1 x2 x3 x4 x5] matrix results following values
d=[z1 z2 z3 z4 z5]
for pair x5 x1 x2 measure z5 z1 z2 (selects minimum value and give output value correspond in y matrix)
x1 x2 x3 z1 z2 z3
x2 x3 x4 z2 z3 z4
x3 x4 x5 z3 z4 z5
x4 x5 x1 z4 z5 z1
for e.g y= [2 3 1 5 6]
d= [2 1 5 4 3]
in pair 6 2 3 (Y matrix), 3 gives less output 1 compared to 2(2) and 6(3). the output must 3.
Kindly help me. i will be highly thankful to you
with best regards.
mudasir ahmed

채택된 답변

Guillaume
Guillaume 2016년 1월 5일
Here is a simple way to generate your triplets (they're not pairs!):
triplets = @(v) [circshift(v, [0 1]); v; circshift(v, [0 -1])]';
And here is how to get your output:
y = [2 3 1 5 6];
d = [2 1 5 4 3];
triplets = @(v) [circshift(v, [0 1]); v; circshift(v, [0 -1])]';
ytriplets = triplets(y)
dtriplets = triplets(d)
[~, col] = min(dtriplets, [], 2);
out = ytriplets(sub2ind(size(ytriplets), [1:size(ytriplets, 1)]', col))

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by