Effacer les filtres
Effacer les filtres

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 vues (au cours des 30 derniers jours)
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

Réponses (1)

Image Analyst
Image Analyst le 22 Oct 2016
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.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by