I want to get the difference between the present number and the previous number for 1000 set of data from the plot.
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Surabhi A S
il 22 Ago 2022
Commentato: Surabhi A S
il 23 Ago 2022
For example,
I have considered 10 random values from the set of 1000 values
X-axis values are as given a = [ -9.658 -9.321 -8.979 -8.742 -8.247 -7.291 -6.738 -7.439 -8.733 -8.596 ]
Y-axis values are as given b = [134 135 136 137 138 139 140 141 142 143 ]
I want to consider each set of values and find the difference between the number and its previous number for example a2-a1,a3-a2,a4-a3.... till a1000-a999. Depending upon these values if its increasing(difference is positive) or decreasing(difference is negative) or constant(difference is zero) I have to find out the threshold value of the given set. Please help me with the code.
0 Commenti
Risposta accettata
Cris LaPierre
il 22 Ago 2022
Do you mean a2-a1,a3-a2,a4-a3,...., a1000-a999?
a = [ -9.658 -9.321 -8.979 -8.742 -8.247 -7.291 -6.738 -7.439 -8.733 -8.596 ];
c=diff(a)
3 Commenti
Cris LaPierre
il 22 Ago 2022
I don't understand why you need a while loop to do that. Diff uses exactly the formula you wrote.
Y = diff(X) calculates differences between adjacent elements of X along the first array dimension whose size does not equal 1:
- If X is a vector of length m, then Y = diff(X) returns a vector of length m-1. The elements of Y are the differences between adjacent elements of X.
Y = [X(2)-X(1) X(3)-X(2) ... X(m)-X(m-1)]
Più risposte (1)
the cyclist
il 22 Ago 2022
a = [2 3 5 7 11];
a - a' % All possible differences between pairs of elements of a
7 Commenti
the cyclist
il 23 Ago 2022
I'm confused by your original question, though, which stated that you also needed non-consecutive differences, such as a(4) - a(1) = 5.
But, I'm glad you got it solved.
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!