Question
We have a Nx2 matrix with pieces of consecutive values that we want to obtain the extreme left and right limits: A=[100 200; 101 201; 102 202; 300 400; 801 901; 802 902] we would like to obtain a matrix with limits (left column and right column) in the detected consecutive sequences of the first column. The isolated sequences (in this case [300 400] should be also retrieved. for A the result would be; B=[100 202; 300 400; 801 902] ;
Expert Answer
Prashant Kumar
PhD Expert
Answered Aug 14, 2026
You haven't clearly defined what consecutive values means mathematically. I'm assuming a difference of 1. Also you haven't explained if both columns are to be considered independently (and what happen if values are consecutive in one column and not the others). I'm assuming that both columns have the exact same pattern so we can ignore column 2 for finding consecutive values.
A=[100 200; 101 201; 102 202; 300 400; 801 901; 802 902]; %finding start and end of consecutive runs. Only using 1st column for that transitionrows = find(diff([-Inf; A(:, 1); +Inf]) ~= 1); %not consecutive when difference is not 1 startseqrows = transitionrows(1:end-1); %start row of consecutive run endseqrows = transitionrows(2:end) - 1; %end row of consecutive run B = [A(startseqrows, 1), A(endseqrows, 2)]
100% Run Guarantee
3-Hour Fast-Track Delivery
Need a Custom Version or Complete Simulation for This Problem?
Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.
Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here
Related matlab Questions & Solutions
Browse All →
Explore similar technical troubleshooting questions and verified MATLAB solutions:
Ready-to-Run MATLAB & Simulink Projects
Browse All Projects →