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.
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Clocks and Timers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!