Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
The simplest way to intersect some intervals ?

Subject: The simplest way to intersect some intervals ?

From: Abel

Date: 27 Jun, 2013 09:21:05

Message: 1 of 2

Hi,

Let's say I have this interval :

A=[1:4];

And this matrix :

X=[1 4;
2 3;
3 5;];

What I want is to intersect A with each line of X, each line being counted as an interval of integers : for example I want [1 4] to be processed as [1:4], [2 3] as [2:3] ect.

intersect(A,[2:3]) works of course and returns : 2 3 but it is not possible to do something like intersect(A,X). How could I do this and, if possible, without using a for loop ?

Subject: The simplest way to intersect some intervals ?

From: Jan Simon

Date: 28 Jun, 2013 10:10:09

Message: 2 of 2

Hi Abel,

I'm not sure what the desired output is. But I guess:

  A = 1:4;
  X =[1 4;
        2 3;
        3 5];

  Y = [min(A(1), X(:, 1)), max(A(end), X(:, 2)];

Kind regards, Jan

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us