when i code using iteration an error occurs saying "the varable "Q2"appears to change size in every loop iteration(within a script).consider preallocating for speed" so how to deal with this issue. :)
1 次查看(过去 30 天)
显示 更早的评论
r1=15.67; r2=63.64; r3=20.996; E1=30; E2=18; E3=9; n=1; Ej(n)=(E1+E2)/2; while Ej(n)<E1 && Ej(n)>E3 , n=1:.1:50; Q1(n)=(E1-Ej(n))/r1; Q3(n)=(Ej(n)-E3)/r3; if Ej>E2,Q2(n)=(E2-Ej(n))/r2; dQ(n)=Q1(n)-Q2(n)-Q3(n); else Q2(n)=(Ej(n)-E2)/r2; dQ(n)=Q1(n)+Q2(n)-Q3(n); end if dQ(n)>0.001; Ej(n+1)=EJ(n)+0.1; elseif dQ(n)<-0.001, Ej(n+1)=Ej(n)-0.1; else break end disp([Ej(n),dQ(n)]); end
0 个评论
回答(1 个)
Image Analyst
2016-10-22
You can just ignore it - it won't matter much for 491 array elements. Or replace these lines
while Ej(n)<E1 && Ej(n)>E3 ,
n=1:.1:50;
with these:
numElements = numel(n);
Ej = zeros(1, numElements);
Q1 = zeros(1, numElements);
Q2 = zeros(1, numElements);
Q3 = zeros(1, numElements);
dQ = zeros(1, numElements);
while Ej(n)<E1 && Ej(n)>E3 && n <= 50
n= n + 0.1;
Actually you need to fix the n lines either way.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!