I have a large dataset and i want to compute the gradient for between two corresponding data and their corresponding times for a large data.
time data
20 6.6
30.3 7.2
41 -8.6
. .
. .
for a large dataset i want to do
A = (7.2 - 6.6) / (30.3 - 20) and store all output in a column format in A.
I tried to use a for loop but my output is not what it needs to be

 채택된 답변

Davide Masiello
Davide Masiello 2022년 11월 3일

0 개 추천

Just do
A = diff(data)./diff(time);

추가 답변 (1개)

Jan
Jan 2022년 11월 14일

1 개 추천

The command gradient(x, t) solves this similar to diff(x) ./ diff(t), but with using the 2-sided difference except for the margins. This replies the same number of elements as the input and is numerically more stable.

카테고리

도움말 센터 및 File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

제품

릴리스

R2022b

질문:

2022년 11월 3일

댓글:

2022년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by