How to count the maximum and minimum range of non-zeros elements?

I
ishitaisha6840 · Dec 28, 2020 · 1.9K views
Question
let's suppose we have A of length 50 rows how we can calculate the maximum range of non-zeros element and as well as minimum A = [0 0 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 ] In this case Max and Min should be, Max = 5 Min = 2   Is there a straightforward solution to do this? without using complex looping because in my case data is too large approximately length of A is 220079705, your kind consideration will be highly regarded by all means,
Expert Answer
Profile picture of Prashant Kumar
Prashant Kumar PhD Expert
Answered Aug 31, 2026
Use regionprops(), in the Image Processing Toolbox:
 
 
 
A = [0 0 1 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 ]
props = regionprops(logical(A), 'Area');
allLengths = [props.Area];
minLength = min(allLengths)
maxLength = max(allLengths)
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

Get a Free Consultation or a Sample Assignment Review!