Highest value number in a repeating array of ascending numbers

조회 수: 1 (최근 30일)
Elise Mangin
Elise Mangin 2022년 1월 19일
댓글: Elise Mangin 2022년 1월 19일
Hi everone,
The data I'm working with is given as a list of numbers that always starts at 1 and increases consecutively to some value, then starts back over at 1 again. Each individual number has its own row in a single column.
For example
1
2
3
1
2
3
4
5
1
2
In this list there are three groups of interest: the group 1-3 (3 max number), 1-5 (5 max number), and 1-2 (2 max number).
I am trying to write a program that spits out the maximum value of each group of consecutive numbers. I've tried a few strategies but am having trouble formatting the data. Any help is very much appreciated!!
  댓글 수: 2
Stephen23
Stephen23 2022년 1월 19일
A = [1;2;3;1;2;3;4;5;1;2;3;4;5;6;1;2];
B = A([diff(A)<0;true])
B = 4×1
3 5 6 2
Elise Mangin
Elise Mangin 2022년 1월 19일
This works great too, and I understand the logic behind it. Thank you!

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

채택된 답변

DGM
DGM 2022년 1월 19일
If those simple rules can be depended upon, then
A = [1;2;3;1;2;3;4;5;1;2;3;4;5;6;1;2];
seqpeaks = A(circshift(A==1,-1))
seqpeaks = 4×1
3 5 6 2
  댓글 수: 1
Elise Mangin
Elise Mangin 2022년 1월 19일
This works beautifully!!! Thank you so much, I was unaware of this circshift fuction.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by