for loop for permutations of for length of array

1 回表示 (過去 30 日間)
Qiana Curcuru
Qiana Curcuru 2021 年 7 月 22 日
編集済み: Qiana Curcuru 2021 年 7 月 22 日
I have a list of items where the total number of items in the list changes depending on the iteration. theres always at least 2 items, and could be as high as 7. i want a forloop to run that will run until every combination of 2 in the list has completed. ex.
a=[a,b,c]
% i need this to run for
%ab
%ac
%bc
for i=1:nchoosek(length(a),2)
%*call a
a(1)
%*call b
a(2)
%repeat with
%a(1) and a(3)
%and
%a(2) and a(3)
end

採用された回答

Matt J
Matt J 2021 年 7 月 22 日
List=nchoosek([a,b,c],2);
for i=1:size(List,1)
p1=List(i,1);
p2=List(i,2);
...
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by