For loop every combination

Hello community,
I want for loops to check every element from 1 to n with all other elements. so letst say n=4
So I want to check Number 1 with 2,3 and 4// check number 2 with 3 and 4// and check number 3 with 4.
Can I build one or maybe two for loops for something like that?

2 件のコメント

Scott MacKenzie
Scott MacKenzie 2021 年 6 月 16 日
Please explain what you mean by "check".
When you say "check Number 1 with 2,3 and 4" what sort of operation or result are you contemplating?
gamer
gamer 2021 年 6 月 16 日
編集済み: gamer 2021 年 6 月 16 日
Hey Scott,
so I ve got a matrix v = rand(n,2) and p = rand(n,2) .
for h =1:1000
p = p+v;
But if p(i,:) is in the near of p(j,:), they should switch the value of v. Now I will make an example for row i = 1 and i =4.
if norm(p(1,:)-p(4,:)) <= 2*r
v(1,:) = temp1
v(1,:) = v(4,:)
v(4,:) = temp1
end
end
And I know i want to verify the norm for every rows with all others. And then swaping the v of these rows, if the if statement is true. So I think I have to use two for loops, but I am not sure.

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

回答 (1 件)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021 年 6 月 16 日

0 投票

Go over this help documentation and will understand how and what to do with [for ... end] loop iteration
https://www.mathworks.com/help/matlab/ref/for.html

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2021 年 6 月 16 日

編集済み:

2021 年 6 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by