Stepwise substraction of all elements of a vector

1 Ansicht (letzte 30 Tage)
Christian
Christian am 19 Jan. 2017
Kommentiert: Christian am 19 Jan. 2017
Hello everybody!
I have a Vector (720x1 double) and I would like to find the values where the delta is the biggest. So I want matlab to do the following:
(720,1)-(719,1)
(719,1)-(718,1)
.
.
.
How can I generate a vector, which contains this stepwise substraction?
So that all I need to do is, find the biggest value of this vector!
Thank you
Cheers
Christian

Akzeptierte Antwort

John BG
John BG am 19 Jan. 2017
Bearbeitet: John BG am 19 Jan. 2017
Hi Christian
The Star Strider answer wouldn't catch a narrow (negative) notch on a fairly flat signal because it would give as peak the flat plateau while the (negative) delta would get through unnoticed.
Since you mention 'values' in plural I suggest you use abs and findpeaks along with diff the following way
v=randi([-10 10],1,720);
w=abs(diff(v))
[peaks,loc_peaks]=findpeaks(abs(diff(v)),'MinPeakHeight',19)
stem(v);hold all;
plot(w)
plot(loc_peaks,peaks,'sg')
.
the field MinPeakHeight set to 19 catches just a few deltas. If you reduce this threshold too low too many peaks will show up and if you set it too high the function findpeaks doesn't get any.
I recommend you have a look at MATLAB help for function findpeaks because it has many optional fields to help choose what peaks to capture.
Christian
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer of any help solving your question,
please click on the thumbs-up vote link,
thanks in advance
John BG
  1 Kommentar
Christian
Christian am 19 Jan. 2017
John, thank you very much! That works perfectly for me :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Star Strider
Star Strider am 19 Jan. 2017
Bearbeitet: Star Strider am 19 Jan. 2017
If I understand correctly what you want to do, this will work:
v = randi(1000, 720, 1); % Create Data
[dvmax,dvmax_idx] = max(diff(v))
dvmax =
969
dvmax_idx =
333
The max function will find and return the value and index of the first occurrence of the maximum. If there are more and you want all of them, use the find function:
dvmax_idx = find(diff(v) == max(diff(v)))
You would have to find the value of the maximum with a separate call to max.
  3 Kommentare
Star Strider
Star Strider am 19 Jan. 2017
Thank you Adam.
Christian
Christian am 19 Jan. 2017
Thank you, that works as well! :)

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by