hello professionals ..i have aattached my code plz suggest me why it is not displaying value of kp2 and e

4 visualizaciones (últimos 30 días)
kp2=rand(10);
e=rand(10);
for i=1:length(50)
r=e(i)*dp-kp1*kp2(i)*(p-1);
if r==1
break;
end
end
here dp , kp1 and p are previously calculated.in this code value come in fraction and it doesnot enter the for if loop...plz suggest me code

Respuesta aceptada

Cedric
Cedric el 12 de Abr. de 2013
Editada: Cedric el 12 de Abr. de 2013
Where do you define M ? At this point it crashes because M is undefined.
A few additional points:
  • You should not name one of your variable "range" as it is the name of an existing function.
  • length(50) in the outer FOR loop is not 50 but 1; I guess that you wanted for i=1:50 actually.
  • if r==1 end does nothing. If you want to quit the loop if r is 1, you want to implement use BREAK in the statement: if r==1, break; end.
  • The inner FOR loop uses the same loop index variable i as the outer FOR loop; this cannot work (both loops will interfere), so you'll want to change it for e.g. k.
  • Don't clear all within your function, it will clear the input args p and q.
EDIT: thank you Walter for the edition, I hadn't seen that it was a function.

Más respuestas (0)

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Community Treasure Hunt

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

Start Hunting!

Translated by