function strc=funstr2(str1,str2)
clc,
%检验参数是否是字符串
ls1=length(str1);
for i=1:ls1
if ~ischar(str1(i))
error('Input must be string');
end
end
ls2=length(str2);
for i=1:ls2
if ~ischar(str2(i))
error('Input must be string');
end
end
slen=ls1+ls2;
A=NCHOOSEK(1:slen,ls1);
[m,n]=size(A);
A1=zeros(m,slen);
for i=1:m
for j=1:n
A1(i,A(i,j))=1;
end
end
strc=cell(m,1);
for ir=1:m
ic=1;
i1=0;
i2=0;
output=[];
while ic<=slen;
if(i1<=ls1)&(A1(ir,ic)==1);
i1=i1+1;
output(ic)=str1(i1);
else if (i2<=ls2)&(A1(ir,ic)==0)
i2=i2+1;
output(ic)=str2(i2);
end
end
ic=ic+1;
end
strc{ir,1}=char(output);
end
温馨提示:答案为网友推荐,仅供参考