Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab递归循环_Matlab_Loops_Categorical Data - Fatal编程技术网

Matlab递归循环

Matlab递归循环,matlab,loops,categorical-data,Matlab,Loops,Categorical Data,我有一个单元格,其中包含分类变量的不同唯一值的单元格。假设这个单元叫做r,在r{1,1}中,我们有第一类,包括“a”,“b”,“c”,在r{1,2}中,我们有“high”,“low”,等等 我的问题是如何做一个循环来得到所有可能的分类组合。我无法使用allcombs函数,因为r中的每个单元格必须单独输入。我需要在一个更大的函数中创建这个循环 将此代码放入myFunc.m中,并在与其他单元格数组嵌套的单元格数组上调用myFunc function myFunc(cellArray) %D

我有一个单元格,其中包含分类变量的不同唯一值的单元格。假设这个单元叫做r,在r{1,1}中,我们有第一类,包括“a”,“b”,“c”,在r{1,2}中,我们有“high”,“low”,等等


我的问题是如何做一个循环来得到所有可能的分类组合。我无法使用allcombs函数,因为r中的每个单元格必须单独输入。我需要在一个更大的函数中创建这个循环

将此代码放入myFunc.m中,并在与其他单元格数组嵌套的单元格数组上调用myFunc

function myFunc(cellArray)

    %Do some stuff

    [I,J] = size(cellArray);
    %if they are both 1 then you know to stop the recursion
    if(I>1 || J > 1)
        for i = 1:I
            for j = 1:J
                myFunc(cellArray{i,j})
            end
        end
    end
end

将整个单元格数组粘贴到一个单元格中,生成一个递归函数,在每个单元格上循环并调用自身,然后您可以在最外层的单元格上调用该函数。请注意,此网站不是代码编写服务,如果您不懂该语言,请查找联机教程或其他内容。在将来,您需要包含一个代码示例,我们可以帮助您填充空白。