Hello, my task is simple i want to divide my signal into number x parts, where x is when the difference between the last nonzero value and the next to be found should be greater than a threshold, T. I tried to implement this but i always get the new result to be the same, my vector is not divided into subvectors.
s1=[0,1,2,5,0,0,5,3,0,0,0,0,3,4,1,2];
h=0;
T=4;
for kk=1:length(s1)-1
if diff([s1(kk) s1(kk+1)])<T
h=h+1;
P{h}=[s1(kk):s1(kk+1)];
end
end
Any suggestion wellcomed, or shoould i use combine the find with the unique functions? thank you.

5 件のコメント

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 1 月 7 日
Can you post the expected result?
Manolis Michailidis
Manolis Michailidis 2016 年 1 月 7 日
編集済み: Manolis Michailidis 2016 年 1 月 7 日
yes, for the specified T i should get 2 subvectors A=[0,1,2,5,0,0,5,3] and B=[3,4,1,2]
Walter Roberson
Walter Roberson 2016 年 1 月 7 日
Is this referring to the difference in position or the difference in value ?
hemalatha
hemalatha 2016 年 1 月 8 日
which basis you are getting the subvectors?.Because in your vector you are having 7 zeroes and the subvectors contains only 3 zeroes.how it is?
Walter Roberson
Walter Roberson 2016 年 1 月 8 日
hemalatha, notice that the break is taken at the point where there are T zeros in a row. I suspect that is what the poster is asking about, difference in position rather than difference in value itself.

サインインしてコメントする。

 採用された回答

goerk
goerk 2016 年 1 月 8 日

0 投票

s1=[0,1,2,5,0,0,5,3,0,0,0,0,3,4,1,2];
signalID = cumsum([0 diff(s1)>4]);
nofSignals = signalID(end)+1;
for i=1:nofSignals
P{i}=s1(signalID==i-1);
end

その他の回答 (0 件)

カテゴリ

質問済み:

2016 年 1 月 7 日

回答済み:

2016 年 1 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by