Error using str2func Error: This statement is incomplete
Show older comments
Hi all,
I am trying to implement a matlab script that builds an in-text recursive function funct based on the number of input n. However, str2func in matlab throws an error like so
" Error using str2func
Error: This statement is incomplete"
at the line:
funct{m} = str2func(strcat(strt,res,enstr));
when n >= 3. Please can some help out here. The full script is below. I know something is off about the loop but I just cant put my finger on what exactly I am doing wrong.Thanks alot.
n = 3;
funct = cell(n,1);
funct{n} = @(x,d,k,g,v,funct) exp(1i*kz(n)*x);
funct{n-1} = @(x,d,k,g,v,funct) exp(1i*kz(n-1)*x)./(1-r(n-1,2)*...
r(n-1,1)*exp(2*1i*kz(n-1)*x));
for m = n-2:-1:1
strt = strcat('@(x,d,k,g,v,funct) exp(1i*kz(',num2str(m),...
')*x)/(1-r(',num2str(m),',1)*r(',num2str(m),',2)*exp(2i*kz(',...
num2str(m),')*x) - r(',num2str(m),',1)*exp(2i*kz(',num2str(m),...
')*x)*(');
res = '';
for l = m+1:n-1
prodp = '';
for p = m:l-1
prodp = strcat(prodp, '(tFPcal(',num2str(p+1),...
')*exp(1i*kz(' ,num2str(p+1),')*d(',num2str(p+1),...
'))*...t(',num2str(p),',2)*t(',num2str(p+1),',1)',')*');
end
prodp = prodp(1:length(prodp)-1);
res = strcat(res, 'r(',num2str(l),',2)*(', prodp, ')+');
end
res = res(1:length(res)-1); enstr = '))';
funct{m} = str2func(strcat(strt,res,enstr));
end
%% Output handling
output1 = funct
Accepted Answer
More Answers (0)
Categories
Find more on Communications Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!