What is the problem with this for loop?

1 visualización (últimos 30 días)
kintali narendra
kintali narendra el 5 de Jun. de 2016
Editada: per isakson el 6 de Jun. de 2016
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.

Respuestas (1)

Roger Stafford
Roger Stafford el 5 de Jun. de 2016
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 comentarios
kintali narendra
kintali narendra el 5 de Jun. de 2016
Roger Stafford I made the above modification but there is no improvement. It is still the same
Roger Stafford
Roger Stafford el 5 de Jun. de 2016
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Clocks and Timers en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by