フィルターのクリア

Repetition of values number of times

1 回表示 (過去 30 日間)
Offroad Jeep
Offroad Jeep 2016 年 2 月 4 日
コメント済み: Guillaume 2016 年 2 月 5 日
Attach please find the code . it is repeatedly giving the value where i only want one time random dtheta and it should not repeat the value for 25 times... Thanks
  2 件のコメント
Stephen23
Stephen23 2016 年 2 月 5 日
Guillaume
Guillaume 2016 年 2 月 5 日
Most likely, they are related. In either case, the code is full of mistakes and it's impossible to know the original intent. So the answer is the same, if you can't see what is wrong with your code, step through it with the debugger.

サインインしてコメントする。

採用された回答

Kelly Kearney
Kelly Kearney 2016 年 2 月 4 日
The code (in the future, it's more convenient for readers if you post short code snippets like this, rather than including them as attachments):
m = 5
B = linspace(2,0,10)
theta = 0
nmc = 25
dtheta = [0 rand(1,nmc-2)*5]
for i = 1:length(B)
for j = 1:nmc
theta_new = theta+dtheta
mag_new = m * cosd(theta_new)
end
end
What exactly do you want this code to be doing? The loops right now are completely unnecessary; nothing changes in the loop, so you're just repeating the same calculation 250 times. Add some semicolons to suppress the (repeated) output, and drop the loops:
m = 5;
B = linspace(2,0,10);
theta = 0;
nmc = 25;
dtheta = [0 rand(1,nmc-2)*5];
theta_new = theta+dtheta;
mag_new = m * cosd(theta_new);
However, in this version, several of your variables ( B, nmc) are unused.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by