フィルターのクリア

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 Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by