how we can program ring topology

2 vues (au cours des 30 derniers jours)
Mudasir Ahmed
Mudasir Ahmed le 28 Juin 2015
Commenté : Mudasir Ahmed le 28 Juin 2015
hi.
i want to write a program in which i have a series of variables
x=[x1 x2 x3 x4 x5]
the neighbors of x1 are x2 and x5, for x2 (x1 and x3) for x3 (x2 and x4) for x4 (x3 and x5) for x5 (x4 and x1).
how i program this for sharing of information. means every variable compare its value to its adjacent variable. if any of both have larger value then replaced larger value with by its own value kindly help me.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 28 Juin 2015
Mudsair - it seems that you just need some kind of "sliding window" to operate on your array. For example, you could do the following assuming that that x is your input array
for k=1:length(x)
% get the left and right indices of k to do the comparison
if k==1
idxLeft = length(x);
idxRight = k+1;
else if k==length(x)
idxLeft = k-1;
idxRight = 1;
else
idxLeft = k-1;
idxRight = k+1;
end
% now compare
if x(k) > x(idxLeft)
% do something
end
if x(k) > x(idxRight)
% do something
end
end
The do something part is up to you. Should x be updated directly, or should you update a copy of x?
  1 commentaire
Mudasir Ahmed
Mudasir Ahmed le 28 Juin 2015
Thanks Allot sir :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Special Functions dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by