Problem 512. Spot the rectangle
This problem is related to the 17x17 challenge. Given a matrix filled with ones and zeros, determine whether or not any rectangles are present. A rectangle is a formed whenever four ones appear in the corners of a rectangular region of the matrix.
Examples:
Input a = [ 1 0 0 0 0
0 0 0 1 0
0 0 0 0 1
0 0 0 0 1
0 0 1 0 0 ]
Output tf is false
You can't form any rectangles here.
Input a = [ 1 0 1 0
0 0 1 0
1 0 1 0
0 0 1 1 ]
Output tf is true
There is a rectangle: a([1 3],[1 3]) is [1 1; 1 1]
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Ned Gulley
on 14 Jan 2015
I added a rectangular (non-square) test case. Thanks for the note.
Christian Schröder
on 28 Sep 2022
Could you add
a = ones(3) - eye(3)
to the test suite?
Abdelrahman Adel
on 7 Apr 2024
It was a good problem.
If anyone find it's difficult , you can download my answer
http://up-4.net/d/tt5L
Solution Comments
Show commentsGroup

Matrix Patterns I
- 18 Problems
- 60 Finishers
- Pascal's Matrix
- Spot the rectangle (Part 2)
- Spot the rectangle
- Create Volcano (or Atoll) martix. It is an extension of Bullseye matrix problem.
- Magic is simple (for beginners)
- Create Volcano (or Atoll) martix. It is an extension of Bullseye matrix problem.
- Mirror Image matrix across anti-diagonal
- Special matrix
- Make a logical diamond using GALLERY function
- Magic is simple (for beginners)
- Create a Multiplication table matrix...
- Make a Star Pyramid
- "mirror" matrix
- Twist 'n' Match
- Create a matrix X, where each column is a shifted copy of the vector v
- Symmetric matrix
- Create a patchwork matrix
- Spiral In
- Spot the rectangle (Part 2)
- Spot the rectangle
- Matrix spiral
- Better bullseye matrix
Problem Recent Solvers138
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!