Error: The expression to the left of the equals sign is not a valid target for an assignment.

my code is:
N = [12,15,16,11,11,9];
P = [5,12,7,2,1,1];
N = N';
P = P';
N_evoluz_tempo = zeros(Nx,Nx*n)
N_n1 = B*N + (alfa*(1-N)- P)*N'*dt
P_n1 = C*P + (N_n1 - mu)*P*dt
N_evoluz_tempo = N_n1
P_evoluz_tempo (:,1) = P_n1
k=0; c=0;
for j = 2:n
{
N_n1 = B*N_n1 + (alfa*(1-N_n1)-P_n1)*N_n1*dt
P_n1 = C*P_n1 + (N_n1 - mu)*P_n1*dt
elemento = N_evoluz_tempo(1,j)
}
if (elemento==c)
{
N_evoluz_tempo (:,i)= N_n1;
k=i;
}
else
{%
while (N_evoluz_tempo (:,k)==0)
k+1;
N_evoluz_tempo (:,k)= N_n1;
}
end
end
P_evoluz_tempo(:,i)= P_n1
}
end
Matlab returns error for the assignement: elemento = N_evoluz_tempo(1,j), and also N_n1 = B*N_n1 + (alfa*(1-N_n1)-P_n1)*N_n1*dt P_n1 = C*P_n1 + (N_n1 - mu)*P_n1*dt
where B, C and N_n1 are 6x6 matrix and P_n1 is a 6x1 array. What is the problem with my assignment?

Respuestas (2)

1. Terminate the lines with ; to avoid printing on screen, which consumes time.
2. You should not use flower braces inside loops, ({}), they have different purpose.
3. Still your code is a mess and you need to rethink over it.
N = [12,15,16,11,11,9];
P = [5,12,7,2,1,1];
N = N';
P = P';
N_evoluz_tempo = zeros(Nx,Nx*n) ;
N_n1 = B*N + (alfa*(1-N)- P)*N'*dt ;
P_n1 = C*P + (N_n1 - mu)*P*dt ;
N_evoluz_tempo = N_n1 ;
P_evoluz_tempo (:,1) = P_n1 ;
k=0; c=0;
for j = 2:n
N_n1 = B*N_n1 + (alfa*(1-N_n1)-P_n1)*N_n1*dt ;
P_n1 = C*P_n1 + (N_n1 - mu)*P_n1*dt ;
elemento = N_evoluz_tempo(1,j) ;
if (elemento==c)
N_evoluz_tempo (:,j)= N_n1;
k=j;
else
while (N_evoluz_tempo (:,k)==0)
k+1;
N_evoluz_tempo (:,k)= N_n1;
end
end
P_evoluz_tempo(:,j)= P_n1 ;
end
{ and }
are not valid syntax in Matlab. Putting these around the body of your for loop is what is leading to errors whose message appears to make no sense. Get rid of the curly braces and it should work fine (though I've only glanced down the code, I can't guarantee there are no other errors).

Etiquetas

Preguntada:

el 6 de Jul. de 2017

Comentada:

el 6 de Jul. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by