Borrar filtros
Borrar filtros

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 visualizaciones (últimos 30 días)
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

Respuestas (1)

Image Analyst
Image Analyst el 22 de Oct. de 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.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by