Matlab的递归相关疑问

1,输入一个字符串,打印出该字符串中字符的所有排列。例如输入字符串abc,则输出由字符a、b、c所能排列出来的所有字符串abc、acb、bac、bca、cab和cba。
2,给出一个正整数a,要求分解成若干个正整数的乘积,并且按大小顺序输出,问这样的分解的种数有多少(注意,a=a也是一种分解)。
这个我尝试了这样的,效果不理想


%% 待理解
clear;clc;
%% 调用区域
global a;
n=input("甲");
while(n)
a=0;
ss=input("乙");
fun(2,ss);
fprintf("%d\n",a);
n=n-1;
end
%% 函数部分
function []=fun(x,y)
global a;
if(y==1)
    a=a+1;
    return
else
    for i=x:y
        if(mod(y,i)==0)
            fun(i,y/i);
        end
    end
end
end

3,给出一个正整数a,要求分解成若干个正整数的和,并且按大小顺序输出,问这样的分解的种数有多少(注意,a=a也是一种分解)。

希望使用“函数+调用代码”的方法解决这三个示例

Str = 'FBECGHD'; 
function []=fun(Str)
A =perms(Str) ; 
B = {}; 
index = 1; 
while true 
    try 
     substring = A(index,:); 
     B{index}=substring; 
     index = index + 1; 
    catch 
     break 
    end 
end 
C = unique(B) 

拿我准备数模的经验来看,2和3的话可以考虑
用动态规划,我就写一下递归式吧
int f(int a,int min)表示把a分解为大于等于min的因数有多少种分法
int f(int a,int min){
if(a < min){
return 0;
}
int result = 1;
for(int i = min;iif(a % i == 0){
result += f(a/i,i);
}
}
return result;
}
f(a,2)就是想要的结果

然后matlab这里以前我用过的分解因数的,程序改改就行了,可以拿来参考https://blog.csdn.net/weixin_29927965/article/details/115825163
望采纳谢谢啦