What is the problem with this for loop?

1 次查看(过去 30 天)
deltaK values are should be "zero" for clock time of 0 - 0.999 sec but its giving the values of 0.1.Please help to solve the issue.
function [Out] = LMAImplementation_Motor(In)
persistent eWithNoChange eWithDeltaL eWithDeltaK
e = In(1);
L = In(2);
K = In(3);
Clock = In(4);
clock = int64(Clock)
for clock = 0.000:0.999
deltaK = 0; deltaL = 0;
eWithNoChange(end+1) = e;
sizeofeWithNoChange = size(eWithNoChange);
end
for clock = 1.000:1.999
deltaL = L*0.1; deltaK = 0;
eWithDeltaL(end+1) = e;
sizeofeWithDeltaL = size(eWithDeltaL);
end
for clock = 2.000:2.999
deltaL = 0; deltaK = K*0.1;
eWithDeltaK(end+1) = e;
sizeofeWithDeltaK = size(eWithDeltaK);
end
deltaK
deltaL
Out = [deltaL,deltaK,Clock];
end
I don't understand why the deltaK values is 0.1 even when the clock values in between 0 and 0.999.

回答(1 个)

Roger Stafford
Roger Stafford 2016-6-5
For each of the for-loops ‘clock’ can take only one value. For example, with "for clock = 1.000:1.999", clock can only be 1.000, since the default step size is 1. I think you meant "for = 1.000:0.001:1.999".
  4 个评论
kintali narendra
kintali narendra 2016-6-5
Roger Stafford I made the above modification but there is no improvement. It is still the same
Roger Stafford
Roger Stafford 2016-6-5
You are not using 'clock' anywhere in your for-loops. Your 'e' is zero, so you are stretching 'eWithNoChang' out in long vectors of zeros and nothing else is accomplished. You had better stop and rethink what it is you are trying to do.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Clocks and Timers 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by