其實可以不用判斷,只需要顛倒下順序就可以了:
for g=1:G
BO(1:G,g,i)=-iEs(1:G,g,i)-x(g)/keff_old*ivEf(1:G,i);
%或者不對,冒號用法老混淆,大致這意思
B0(g,g,i)=iEr0(g,i)-x(g)/keff_old*ivEf(g,i);
end
就是說先給包含B0(g,g,i)在內的所有BO賦值,再將第g個替換掉
非要用判斷的話,可以這樣:
for gg=1:G
if gg~=g
BO(gg,g,i)=-iEs(gg,g,i)-x(g)/keff_old*ivEf(gg,i);
或者用while,就比較麻煩了,不推薦
gg=1;
while gg
其實可以不用判斷,只需要顛倒下順序就可以了:
for g=1:G
BO(1:G,g,i)=-iEs(1:G,g,i)-x(g)/keff_old*ivEf(1:G,i);
%或者不對,冒號用法老混淆,大致這意思
B0(g,g,i)=iEr0(g,i)-x(g)/keff_old*ivEf(g,i);
end
就是說先給包含B0(g,g,i)在內的所有BO賦值,再將第g個替換掉
非要用判斷的話,可以這樣:
for g=1:G
B0(g,g,i)=iEr0(g,i)-x(g)/keff_old*ivEf(g,i);
for gg=1:G
if gg~=g
BO(gg,g,i)=-iEs(gg,g,i)-x(g)/keff_old*ivEf(gg,i);
end
end
end
或者用while,就比較麻煩了,不推薦
for g=1:G
B0(g,g,i)=iEr0(g,i)-x(g)/keff_old*ivEf(g,i);
gg=1;
while gg