how to solve Ring topology?

2 Ansichten (letzte 30 Tage)
Mudasir Ahmed
Mudasir Ahmed am 5 Jan. 2016
Beantwortet: Guillaume am 5 Jan. 2016
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

Akzeptierte Antwort

Guillaume
Guillaume am 5 Jan. 2016
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))

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by