code explanation question help!

조회 수: 1 (최근 30일)
william Smith
william Smith 2019년 4월 1일
댓글: william Smith 2019년 4월 1일
%can you please explain what this code is calcuating?
%Thanks!
y= x(find(t > t(i)-0.3))

채택된 답변

Adam Danz
Adam Danz 2019년 4월 1일
편집: Adam Danz 2019년 4월 1일
'i' is an integer, index value. For the sake of the example, let's say i = 4.
t(i) is the 4th value stored in 't'.
t > t(i)-0.3 produces a logical vector of 1s and 0s the same size as 't'. It contains 1s whenever the value of t is greater than the 4th t plus 0.03.
So, if t = [0 1 2 3 4 5 6 7] and i = 4, the logical vector would be [0 0 0 1 1 1 1 1].
find() returns the index values that are true. so, find([0 0 0 1 1 1 1 1]) would return [4,5,6,7,8].
x([4,5,6,7,8]) looks at the fourth, fifith, sixth, seventh, and eighth values of 'x'.
To summarize, that line pulls out a subsection of 'x' based on the values of 't'.
  댓글 수: 9
Adam Danz
Adam Danz 2019년 4월 1일
편집: Adam Danz 2019년 4월 1일
I have a feeling this isn't the full section of code. Now that there's context, I might be able to help you further. Where are you doing the integration? Could you describe x?
william Smith
william Smith 2019년 4월 1일
finding the force that needed to be applied on a mass where i have a broom attached to that mass and swings around (PID design controller problem)
F(i) = k_p*x(i) + k_i*trapz(y), as far as x it represents the angle that the broom swings at.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by