필터 지우기
필터 지우기

What is the problem with this for loop?

조회 수: 1 (최근 30일)
kintali narendra
kintali narendra 2016년 6월 5일
편집: per isakson 2016년 6월 6일
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