Finding max value of 1D vector when all values could be negative
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello, I have a set of numbers and want to identify the largest difference between adjacent values. I have used the diff function and this returns
DD=diff(D) % D is my data,and can be postive or negative!!
DD =
-0.8867
-0.9328
-0.9667
-33.9785
-0.1568
-0.1511
-0.1434
-0.1334
So to identify the largest index and then value, I have to allow for negative values of DD as above - hence the abs below.
This was my 1st attempt, but it diodnt work as the try part didn'f fail.
m=max(abs(DD(:))); % Need the abs to allow for any sign of data
try
idx=find(DD==m)
catch
idx=find(DD==-m)
end
So I tried this which did work: Is there a better way
idx=find(DD==m)
[sy,sx]=size(idx)
if sy==0
idx=find(DD==-m)
end
I then want to list out the highest say 4 values of the differences DD, but again as the signs can be =ve or -ve, I can use the normal sort with ascend / descend, how to do this?
This was my attempt:
X=data(idx,1);
Y=data(idx,col);
sortedDiff=sort(DD,'descend');
sortedDiff(1:5,1)
Réponse acceptée
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!