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. :)

조회 수: 2 (최근 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

답변 (1개)

Image Analyst
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.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by