Stepwise substraction of all elements of a vector

조회 수: 1 (최근 30일)
Christian
Christian 2017년 1월 19일
댓글: Christian 2017년 1월 19일
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

채택된 답변

John BG
John BG 2017년 1월 19일
편집: John BG 2017년 1월 19일
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
Christian
Christian 2017년 1월 19일
John, thank you very much! That works perfectly for me :)

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Star Strider
Star Strider 2017년 1월 19일
편집: Star Strider 2017년 1월 19일
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
Star Strider
Star Strider 2017년 1월 19일
Thank you Adam.
Christian
Christian 2017년 1월 19일
Thank you, that works as well! :)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by