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

4 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Cedric
Cedric il 12 Apr 2013
Modificato: Cedric il 12 Apr 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.

Più risposte (0)

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Tag

Non è stata ancora inserito alcun tag.

Community Treasure Hunt

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

Start Hunting!

Translated by