finding 3 consecutive negative numbers
3 views (last 30 days)
Show older comments
I need to find how many times 3 consecutive negative numbers are in the matrix
A = randi([-4,4], n, n)
where n>2 and n<10.
2 Comments
John D'Errico
on 24 Nov 2015
Edited: John D'Errico
on 24 Nov 2015
Is this homework?
Is this a question of expected value? I.e., the EXPECTED number of such occurrences, or the actual number of these events for a given matrix?
If it is simply a question of counting those events for a given matrix, then learn to use diff to identify when three numbers are consecutive, as well as a test on the entire array to indicate the negative numbers.
Image Analyst
on 24 Nov 2015
That's a 2D array. Do you want consecutive in both columns and rows?
Hints: Process a row or column at a time. Then threshold, then use regionprops and look for blobs with an area of exactly 3.
Answers (0)
See Also
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!