필터 지우기
필터 지우기

Making different combinations from tree branches in matlab

조회 수: 3 (최근 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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by