Repetition of values number of times

2 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 Audio Processing Algorithm Design 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by