how can I find elements in matrix A between elements in matrix B

Hi
with ref to the attached data and plot.
I'm trying to find the find the signal valley points between peaks with the intent of selecting the minimum valleypoint between two consecutive peaks.
so i would have peak,valley,peak
the two matrices are not equal length
i've tried to use find without success and would really appreciate some pointers
A = valley(:,1);
B = peak(:,1);
x = zeros(length(B)-1,1);
for ii = 1:length(B)-1
x = find(A(A>B(ii)) & A(A<B(ii+1)));
end

댓글 수: 2

Did you try to use the function peaks?
Did the code actually works? I think the find command crash because of the dimensions of A(A>B(ii)) and A(A<B(ii+1)) are not the same. Maybe you were trying to do:
x = find((A>B(ii)) & (A<B(ii+1)));
I did not try peaks. im not familiar with that function.
i did try your suggestion, but still had indexing error;
Index exceeds the number of array elements (21).
thanks

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

 채택된 답변

Star Strider
Star Strider 2019년 6월 10일
I would use the discretize (link) and splitapply (link) functions for this. (They were introduced in R2015b.)
D = load('signal_workspace.mat');
A = D.A;
B = D.B;
bin = discretize(A,B);
idx = splitapply(@(x){x}, A, bin);
Then to recover the indices:
ValleyIndices_1 = [idx{1}] % Valleys Between Peak #1 & Peak #2
ValleyIndices_2 = [idx{2}] % Valleys Between Peak #2 & Peak #3
producing:
ValleyIndices_1 =
10522864
ValleyIndices_2 =
10523690
10524012
... and so for the rest.

댓글 수: 2

Star Strider, sorry for the delayed reply.
thanks, exactly what i was trying to do.
i'll need to study the too functions discretize and splitapply to get a better understnding of how these might be used in other circumstances.
cheers
As always, my pleasure.
No worries!

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

추가 답변 (0개)

카테고리

질문:

2019년 6월 9일

댓글:

2019년 6월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by