wordconverter.m

来自「student teacher and proferssor llove thi」· M 代码 · 共 1,499 行 · 第 1/5 页

M
1,499
字号
   repstr='minf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);   outflag(3)=1;  else   outflag(1)=1;  end  %funstr{i},goon,outflag,kb case 'mean'  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);  goon=1;  foo=1;  foo2=0;  %funstr{i},foo,foo2,'what?',kb  if howmany==1                         % One argument   if any(strcmp(typs{11},tempstr))        % 2-D Array argument    ;% Decide what to do based on the shape    if foo     if any(strcmp(tempstr(1),typs{1}))     % Full matrix, just add ,1 to the min statement      funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'(spread(sum(',subscripts{1},',1),1,1)/ubound(',subscripts{1},',1))',funstr{i}(parens(2)+1:length(funstr{i}))];     elseif any(strcmp(tempstr(1),typs{9})) % Row, OK, fortran mins entire thing      funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'(sum(',subscripts{1},')/ubound(',subscripts{1},',2))',funstr{i}(parens(2)+1:length(funstr{i}))];     elseif any(strcmp(tempstr(1),typs{10}))% column, OK, fortran mins entire thing      funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'(sum(',subscripts{1},')/ubound(',subscripts{1},',1))',funstr{i}(parens(2)+1:length(funstr{i}))];     end     goon=0;   outflag(2)=1;    end   elseif any(strcmp(typs{4},tempstr))    % 1-D Array argument    funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'(sum(',subscripts{1},')/ubound(',subscripts{1},'))',funstr{i}(parens(2)+1:length(funstr{i}))];    goon=0;    outflag(2)=1;   else                                   % Scalar argument    funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),funstr{i}((funstrwords_e{i}(j)+1):length(funstr{i}))];    goon=0;    outflag(2)=1;   end  elseif howmany==2                     % Two arguments   if j>1    if strcmp(funstrwords{i}{j-1},'spread')     foo=0; foo2=0;    end   end   [tempval]=determineshape(howmany,subscripts,centercomma,parens,i,j,2);   if ~((tempval==1)|(tempval==2))      foo=0; foo2=1;     end   if foo    temp2=cell(1,2);temp2{1}='';temp2{2}='';    if ~any(strcmp(tempstr(2),typs{5})),temp2{1}='mxs(';temp2{2}=')';end    if tempval==1     temp5{1}='';                temp5{2}='';    else     temp5{1}='transpose(';      temp5{2}=')';    end    if any(strcmp(tempstr(1),typs{1}))     % Full matrix     funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),temp5{1},'(spread(sum(',subscripts{1},',',temp2{1},subscripts{2},temp2{2},'),1,1)/ubound(',subscripts{1},',',temp2{1},subscripts{2},temp2{2},'))',temp5{2},funstr{i}(parens(2)+1:length(funstr{i}))];    elseif any(strcmp(tempstr(1),typs{9})) %Row     if tempval==1      funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),funstr{i}(funstrwords_e{i}(j)+1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];     elseif tempval==2      funstr{i}=[funstr{i}(1:funstrwords_b{i}(j)-1),'(sum(',subscripts{1},')/ubound(',subscripts{1},',2))',funstr{i}(parens(2)+1:length(funstr{i}))];     end    elseif any(strcmp(tempstr(1),typs{10}))% column     if tempval==1      funstr{i}=[funstr{i}(1:funstrwords_b{i}(j)-1),'(sum(',subscripts{1},')/ubound(',subscripts{1},',1))',funstr{i}(parens(2)+1:length(funstr{i}))];     elseif tempval==2      funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),funstr{i}(funstrwords_e{i}(j)+1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];     end    elseif any(strcmp(tempstr(1),typs{4}))% 1-D     funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'(sum(',subscripts{1},')/ubound(',subscripts{1},',1))',funstr{i}(parens(2)+1:length(funstr{i}))];    elseif any(strcmp(tempstr(1),typs{5}))% scalar     funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'(',subscripts{1},')',funstr{i}(parens(2)+1:length(funstr{i}))];    end    goon=0;      outflag(2)=1;   else    if foo2      goon=1;     else      goon=0;     end   end  end  if goon   repstr='meanf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);   outflag(3)=1;  else   outflag(1)=1;  end case 'median'  repstr='medianf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);   outflag(3)=1; case 'sort' case 'sortrows' case 'std' case 'subspace' case 'break'  repstr='exit';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr); case 'sum'  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);  goon=1;  foo=1;  foo2=1;  %funstr{i},'what?',kb  if howmany==1                         % One argument   if any(strcmp(typs{11},tempstr))        % 2-D Array argument    ;% Decide what to do based on the shape    if j>1     if strcmp(funstrwords{i}{j-1},'spread')      foo=0;     end    end    if foo     if any(strcmp(tempstr(1),typs{1}))     % Full matrix, just add ,1 to the sum statement      funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'spread(',funstr{i}((funstrwords_b{i}(j)):parens(2)-1),',1),1,1)',funstr{i}(parens(2)+1:length(funstr{i}))];outflag(2)=1;     elseif any(strcmp(tempstr(1),typs{9})) % Row, OK, fortran sums entire thing     elseif any(strcmp(tempstr(1),typs{10}))% column, OK, fortran sums entire thing     end     goon=0;    end   elseif any(strcmp(typs{4},tempstr))    % 1-D Array argument    %We're fine. Do nothing.    goon=0;   else                                   % Scalar argument    funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),funstr{i}((funstrwords_e{i}(j)+1):length(funstr{i}))];    goon=0;    outflag(2)=1;   end  elseif howmany==2                     % Two arguments   [tempval]=determineshape(howmany,subscripts,centercomma,parens,i,j,2);   if any(strcmp(typs{11},tempstr(1)))     % 2-D Array argument    ;%Then simply make the output an array    if j>1     if strcmp(funstrwords{i}{j-1},'spread')      foo=0; foo2=0;     end    end    [tempval]=determineshape(howmany,subscripts,centercomma,parens,i,j,2);    if ~((tempval==1)|(tempval==2))     foo=0; foo2=1;    end    if foo     if tempval==1      temp5{1}='';                temp5{2}='';     else      temp5{1}='transpose(';      temp5{2}=')';     end     if any(strcmp(tempstr(1),typs{1}))     % Full matrix, just add ,1 to the sum statement      funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),temp5{1},'spread(',funstr{i}((funstrwords_b{i}(j)):parens(2)-1),'),1,1)',temp5{2},funstr{i}(parens(2)+1:length(funstr{i}))];     elseif any(strcmp(tempstr(1),typs{9})) %Row      if tempval==1 %remove sum and 2nd sub       funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),funstr{i}(funstrwords_e{i}(j)+1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];      elseif tempval==2       funstr{i}=[funstr{i}(1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];      end     elseif any(strcmp(tempstr(1),typs{10}))% column      if tempval==1       funstr{i}=[funstr{i}(1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];      elseif tempval==2       funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),funstr{i}(funstrwords_e{i}(j)+1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];      end     end     goon=0;      outflag(2)=1;    else     if foo2      goon=1;     else      goon=0;     end    end   elseif any(strcmp(typs{4},tempstr(1))) % 1-D Array argument    %Chill for now, just remove 2nd sub    goon=0;outflag(2)=1;    funstr{i}=[funstr{i}(1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];   else                                   % Scalar argument    funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),funstr{i}(funstrwords_e{i}(j)+1:centercomma(1)-1),funstr{i}(parens(2):length(funstr{i}))];    goon=0;    outflag(2)=1;   end  end  if goon   repstr='sumf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);   outflag(3)=1;  else   outflag(1)=1;  end  %funstr{i},'what2?',kb case 'trapz' case 'var' case 'char' case 'double'  repstr='dble';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr); case 'cat' case 'single' case 'abs'  outflag(1)=1; case 'acos'  repstr='acosf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'acosh'  repstr='acoshf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'acot'  repstr='acotf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'acoth'  repstr='acothf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'acsc'  repstr='acscf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'acsch'  repstr='acschf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'angle' case 'asec'  repstr='asecf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'asech'  repstr='asechf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'asin'  repstr='asinf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'asinh'  repstr='asinhf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'atan'  repstr='atanf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);    if any(strcmp(tempstr(1),typs{4}))   funstr{i}=[funstr{i}(1:parens(1)),'spread(',subscripts{1},',1,1)',funstr{i}(parens(2):end)];  else   funstr=replaceword(i,j,funstr,funstrwords,funstrwords_b,funstrwords_e,repstr);  end  outflag(3)=1; case 'atan2'  outflag(1)=1; case 'atanh'  repstr='atanhf';fortranfunwords{length(fortranfunwords)+1}=repstr;outflag(1)=1;  [howmany,subscripts,centercomma,parens]=hassubscript(i,j);  tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?