Making different combinations from tree branches in matlab

1 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by