0001 function [r,Pnew,Panew]=AssignFieldErr(r,refpos,N,rho,BNn,ANn)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 if nargin<6
0027 ANn=BNn*0;
0028 end
0029 P=getcellstruct(r,'PolynomB',refpos,1,N);
0030 Pa=getcellstruct(r,'PolynomA',refpos,1,N);
0031
0032 if N==1 && P(1)==0
0033
0034 P=getcellstruct(r,'BendingAngle',refpos);
0035 end
0036
0037 if length(rho)==1
0038 Pnew=repmat(rho.^(N-[1:length(BNn)]),length(P),1).*repmat(P,1,length(BNn)).*repmat(BNn,length(P),1);
0039 Panew=repmat(rho.^(N-[1:length(ANn)]),length(Pa),1).*repmat(P,1,length(ANn)).*repmat(ANn,length(Pa),1);
0040 elseif length(rho)==size(P,1)
0041 RNB=[];
0042 RNA=[];
0043
0044 for irrh=1:size(P,1)
0045 RNB(irrh,:)=rho(irrh).^(N-[1:length(BNn)]);
0046 RNA(irrh,:)=rho(irrh).^(N-[1:length(ANn)]);
0047 end
0048
0049 Pnew=RNB.*repmat(P,1,length(BNn)).*repmat(BNn,length(P),1);
0050 Panew=RNA.*repmat(P,1,length(ANn)).*repmat(ANn,length(Pa),1);
0051 end
0052
0053 for ir=1:length(refpos)
0054 pbold=r{refpos(ir)}.PolynomB;
0055 paold=r{refpos(ir)}.PolynomA;
0056
0057 if ir==1 && length(pbold)>length(Pnew)
0058
0059 Pnew=[Pnew zeros(length(refpos),length(pbold)-length(Pnew))];
0060 Panew=[Panew zeros(length(refpos),length(pbold)-length(Panew))];
0061 end
0062
0063
0064
0065
0066
0067
0068 Pnew(ir,1:length(pbold))=Pnew(ir,1:length(pbold))+pbold;
0069 Panew(ir,1:length(paold))=Panew(ir,1:length(paold))+paold;
0070
0071
0072 r{refpos(ir)}.PolynomB=Pnew(ir,:);
0073 r{refpos(ir)}.PolynomA=Panew(ir,:);
0074 r{refpos(ir)}.MaxOrder=size(Pnew,2)-1;
0075 end
0076
0077
0078 return