Calculating the difference between a vector and time
이전 댓글 표시
I'm looking for a way to get this loop to work, basically I need to calculate the difference in a 3x1 vector divide by the difference in time. Does anyone have any suggestion?
t = 2000
n= 0;
for ind = 0:1:t
n= n+ind;
S(n) = (diff(x( don't know how to input the value here )))./diff(t(ind)); %x is a three element vector
end
댓글 수: 5
dpb
2019년 5월 4일
Afraid you're going to have to show us by an example what you have and what you want and how you get from a) to b); I have no idea what you're trying to explain above, sorry...(and apparently the half-dozen or so before me didn't either)
Nikolaos Zafirakis
2019년 5월 5일
dpb
2019년 5월 5일
dxdt = diff(x)./diff(t);
Nikolaos Zafirakis
2019년 5월 5일
Star Strider
2019년 5월 5일
If you are ‘padding’ ‘A’ with an initial 0, you need to tell MATLAB.
MATLAB does many things well, although it is sadly deficient when it comes to mind-reading.
Try this:
A = [1 1 2 3];
dA = diff([0 A])
producing:
dA =
1 0 1 1
NOTE — You need to do similar ‘padding’ for your time vector.
답변 (1개)
Omer N
2019년 5월 5일
Try this:
A = [1 1 2 3];
A-[0,A(1:end-1)]
ans =
1 0 1 1
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
