【发布时间】:2015-10-13 12:26:37
【问题描述】:
我有一个矩阵,用于使用 ode45 求解方程组。我在 while 循环中迭代地删除一行。但是,我希望第一次迭代“继续”并且不删除任何箭头,以便我可以将删除一个数组的所有结果与使用初始矩阵的结果进行比较。
看起来像:
while smtg
A(pos,:)=0 % Do not compute this line the first iteration
pop=ode45(involving A)
end
我的真实代码:
countrow=0;
A=randi([0 1], 5, 5);
distrib=sum(A,1);
while sum(distrib)>5
countrow=countrow+1;
A(pos,:)=0; % remove one row
options = odeset('RelTol', 1e-4);
[t, pop]=ode45(@Diff,[0 MaxTime],[E I],options,n,m, A);
nbtot =sum(pop(:,n+1:2*n),2);
end
我尝试使用
if countrow==1 % (the first iteration),
continue;
end
但它会跳到第二个结尾并且不计算 nbtot 所以我没有想法......有什么帮助吗?
【问题讨论】:
-
我并不完全清楚您要达到的目标,因此仅供参考:您实际上可以使用
A(pos,:)=[];从矩阵中删除一行(从而减小其大小)。这显然不能解决您的问题,但它可能独立于您的问题有用。 -
不,我希望我的矩阵大小保持不变,因为我在之后绘制矩阵,这就是我使用 A(pos:,)=0; 的原因但我承认,在任何其他情况下,这就是这样做的方式!
标签: matlab loops matrix iteration