Find similar sequences - MATLAB Cody - MATLAB Central

Problem 2640. Find similar sequences

Difficulty:Rate

Another problem inspired by a question on the answers forum.

Given a matrix of positive integer numbers, find all the rows that are similar to the first rows and return these rows as a new matrix.

Rows are considered similar if the numbers common to both rows are in the exact same order with no other numbers in between. 0s in a row are always ignored and only occur at the end of the row.

For example:

 [3 1 5 0 0] and [4 2 1 5 0] are similar (1 5 are the common numbers and occur in the same order)
 [3 1 5 0 0] and [3 4 1 5 0] are not similar (3 1 5 are the common numbers, there's a 4 in between)

Solution Stats

26.4% Correct | 73.6% Incorrect
Last Solution submitted on May 03, 2025

Problem Comments

Solution Comments

Show comments
PIVlab surpasses 100K all-time File Exchange downloads
During the past twelve months, PIVlab, a MATLAB Community Toolbox for particle...
4
8
LLMs with MATLAB updated to support the latest OpenAI Models
Large Languge model with MATLAB, a free add-on that lets you access...
2
4

Group

CodeCrunch 1 Image
CodeCrunch 1
  • 11 Problems
  • 10 Finishers

Problem Recent Solvers114

Problem Tags

Community Treasure Hunt

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

Start Hunting!