I want to create a for loop which creates different pairs each time.

1 vue (au cours des 30 derniers jours)
ME
ME le 5 Mar 2015
Commenté : ME le 5 Mar 2015
for i=1:p
for j=1:p
i~=j
disp('i is equal to');
disp(i);
disp('j is equal to');
disp(j);
end
end
I have made this however some pairs are the same e.g i= 1 j = 1 and so on
  3 commentaires
Greig
Greig le 5 Mar 2015
See Akshata's response below for how to structure the if statement.
As a general rule of good practice, it is better to avoid using i and j and loop indices, MATLAB reserves these for complex numbers (i.e., sqrt(-1)). Use ii and jj instead
ME
ME le 5 Mar 2015
Thank you

Connectez-vous pour commenter.

Réponse acceptée

Chandrasekhar
Chandrasekhar le 5 Mar 2015
Modifié(e) : Chandrasekhar le 5 Mar 2015
for i=1:p
for j=1:p
if (i~=j)
disp('i is equal to');
disp(i);
disp('j is equal to');
disp(j);
end
end
end

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by