[讨论] 请教N个for循环如何实现呢

楼主: balancer12 (Do Something)   2022-12-05 22:37:56
想请教各位大大
我有一个变量A里面可能有三个变异量
在A变异量里面又各有两个变量B
如此总共会有2*2*2=2^3=8组
写法如下
GroupA_numPort=[ 1 2 3 ];
GroupB_CapVariable=[ 10e-6 100e-6 ];
iTest=0;
for i= 1:length(GroupB_CapVariable)
for j= 1:length(GroupB_CapVariable)
for k= 1:length(GroupB_CapVariable)
A_Port=[ GroupB_CapVariable(i) , GroupB_CapVariable(j) , GroupB_CapVaria
ble(k) ] ;
iTest=iTest+1;
end
end
end
因变量A有三个,必须写三次for loop
若变量A变成5、10、99......
不太可能写这么多个for loop@@
请问有什么方式可以实现N个for 循环吗?
谢谢大家指教!
作者: sunev (Veritas)   2022-12-05 22:44:00
你循环内容和B无关吗?看起来像是ndgrid
楼主: balancer12 (Do Something)   2022-12-05 23:08:00
抱歉,修改一下写的范例。主要是想可以产生出2*2*2=8组的组合出来

Links booklink

Contact Us: admin [ a t ] ucptt.com