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

3 ビュー (過去 30 日間)
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

採用された回答

Cedric
Cedric 2013 年 4 月 12 日
編集済み: Cedric 2013 年 4 月 12 日
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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by