필터 지우기
필터 지우기

Martix are updating without entering into "for" loop,

조회 수: 1 (최근 30일)
kintali narendra
kintali narendra 2016년 6월 2일
댓글: kintali narendra 2016년 6월 2일
I Want to eWithDeltaL, eWithDeltaK to be updated during the time intervals mentioned.
function [out] = motor(In)
e = In(1);
%there is some other code
Clock = In(4);
clock = int64(Clock);
for clock = 0:0.999
eWithNoChange = [];
eWithNoChange(end+1) = e;
end
for clock = 1.0000:1.999
deltaL = L*0.1;
eWithDeltaL = [];
eWithDeltaL(end+1) = e;
end
Out = [deltaL,deltaK,clock]

채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 2일
It is being updated: it is having the previous value(s) removed from it and the new value is being stored in it, every iteration of the loop.
What you probably want is to initialize the array once before the loop instead of initializing it in every iteration of the loop. For example,
eWithNoChange = [];
for clock = 0:0.999
eWithNoChange(end+1) = e;
end
Side note:
When you have a for loop, after the loop is finished executing, the index variable (such as clock) is left as the last value that was assigned to it. For example,
for I = 1 : 10
disp(I);
end
then since 10 was the last value assigned to I, after the loop, I will be left as the value 10 .
  댓글 수: 1
kintali narendra
kintali narendra 2016년 6월 2일
I made the changes you mentioned ,but new column is added to matrix without considering the "for" loop.
function [Out] = LMAImplementation_Motor(In)
persistent eWithNoChange eWithDeltaL
Clock = In(4);
clock = int64(Clock);
for clock = 0:0.999
deltaK = 0; deltaL = 0;
eWithNoChange(end+1) = e;
end
for clock = 1.0000:1.999
deltaL = L*0.1;
eWithDeltaL(end+1) = e;
end
Out = [deltaL,deltaK,Clock];

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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