# finding common rang between two different range?

2 views (last 30 days)
shirin mhd on 24 Mar 2022
Commented: shirin mhd on 24 Mar 2022

Hi everyone
I'm new to matlab and because of that my question may be so easy to others.I really appreciate your help.
I have x as my variable. and two range for it as below:
5<x<10
and
-6<x<6
and I want to find common range of them which should be 5<x<6. how can i do this in matlab?
im using version R2015b.

##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Image Analyst on 24 Mar 2022
Edited: Image Analyst on 24 Mar 2022
How about this:
range1 = [5, 10];
range2 = [-6, 6];
minValue = max([range1(1), range2(1)])
minValue = 5
maxValue = min([range1(2), range2(2)])
maxValue = 6
if maxValue >= minValue
% The ranges overlap
commonRange = [minValue, maxValue]
else
% The ranges don't overlap
commonRange = []
end
commonRange = 1×2
5 6
It will work in your antique version.
##### 1 CommentShowHide None
shirin mhd on 24 Mar 2022
thanks alot. it is really helpful for me.

Sign in to comment.

### More Answers (1)

KSSV on 24 Mar 2022
This will work for you:
SEe @Adam Danz answer in the link.
##### 1 CommentShowHide None
shirin mhd on 24 Mar 2022
Thanks alot KSSV.

Sign in to comment.

### Categories

Find more on Desktop in Help Center and File Exchange

R2015b

### Community Treasure Hunt

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

Start Hunting!