Matlab 递归函数只生成所需输出的一半

Matlab 递归函数只生成所需输出的一半,matlab,recursion,Matlab,Recursion,这与 我的解决方案使用递归,但缺少一半所需的输出。这就是我所说的 allinputs = {[1 2] [3 4] [5 6] [7 8]} inputArray = inputBuilder([],allinputs,1) 我可以不用递归就完成这项工作,但我喜欢这种方式,因为它更易于扩展 function inputArray = inputBuilder(currBuild, allInputs, currIdx) inputArray = []; if currIdx <= le

这与

我的解决方案使用递归,但缺少一半所需的输出。这就是我所说的

allinputs = {[1 2] [3 4] [5 6] [7 8]}
inputArray = inputBuilder([],allinputs,1)
我可以不用递归就完成这项工作,但我喜欢这种方式,因为它更易于扩展

function inputArray = inputBuilder(currBuild, allInputs, currIdx)

inputArray = [];
if currIdx <= length(allInputs)

    for i = 1:length(allInputs{currIdx})
        mybuild = [currBuild allInputs{currIdx}(i)];
        inputArray = [inputArray inputBuilder(mybuild,allInputs,currIdx + 1)];

    end

    if currIdx == length(allInputs)
        inputArray = {inputArray mybuild};
    end

end
end
函数inputArray=inputBuilder(currBuild、allInputs、currIdx) 输入阵列=[]; 如果currIdx解决了它

function inputArray = inputBuilder(currBuild, allInputs, currIdx)

inputArray = [];
if currIdx <= length(allInputs)

    for i = 1:length(allInputs{currIdx})

        mybuild = [currBuild allInputs{currIdx}(i)];
        inputArray = [inputArray inputBuilder(mybuild,allInputs,currIdx + 1)];

    end
else
    if isempty(inputArray)
        inputArray = {currBuild};
    else
        inputArray = {inputArray currBuild};
    end
end

end
函数inputArray=inputBuilder(currBuild、allInputs、currIdx) 输入阵列=[];
如果currIdx在调试器中检查代码时发现了什么?@OliverCharlesworth mybuild of[1,3,6,7]似乎被[1,3,6,8]覆盖了。。。但这并不能解释[]数组,其中[1,3,6,7]应该是。我可能对调试的解释完全错误。。。很难通过递归进行跟踪