Making different combinations from tree branches in matlab

2 ビュー (過去 30 日間)
Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 5 月 16 日
回答済み: Sohaib Bin Altaf 2018 年 7 月 5 日
Hello, I have to make all possible combinations from a tree, starting from parent node and ends at the last leaf nodes. I made a code for a fix number of tree branches (4 APs candidate locations),and it worked well for me but i need to make it dynamic so it works for different number of APs depending upon the scenario... Here the dimensions of AP1=[x,y] always, C{1} will be something like {a,b;c,d; e,f;g,h;}, where the length is "j" and from C{2} onward the matrix will be multidimensional... so that's where i need to code efficiently so i can get the desired APconfig.
s=1;
for i=1: length(C{1})
for j=1: length(C{2})
for k=1:length(C{2}{j})
for l=1: length(C{3})
for m=1:length(C{3}{l})
APconfig(s,:)=[{Ap1} {C{1}(i,:)} {C{2}{j}(k,:)} {C{3}{l}(m,:)}];
s=s+1;
end
end
end
end
end

採用された回答

Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 7 月 5 日
I tried and this code worked for me.
for i=1:length(C{1})
combination(i,:)= [{Ap1} {C{1}(i,:)}]
end
i=1
for x=2:length(C)
if x==2
;
else
combination=comb2
comb2={}
i=1 %adjust
end
for y=1:length(C{x})
for z=1:length(C{x}{y})
comb2(i,:) = [combination{ y ,:} {C{x}{y}(z,:)}];
i=i+1;
end end end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by