Skip to Main Content Skip to Search
Login
File Exchange
MATLAB Newsgroup
Link Exchange
  Blogs  
 Contest 
MathWorks.com

Thread Subject: Simplify an array

Subject: Simplify an array

From: Uwe Gallaun

Date: 21 Nov, 2007 08:22:18

Message: 1 of 4

dear matlab users

array=
[1] [2]
[3] [4]
[5] [7]
[6] [7]
[7] [8]
[9] [10]
[10][11]
now i'm trying to look if the numbers in the first column
growing with increment 1.
as result i want to display this array:
result=
[1] [2]
[3] [4]
[5] [8]
[9] [11]

for example:
three points
[5] [7]
[6] [7]
[7] [8]
i'm trying to simplify it to get the start and the end:
[5] [8]

how can i get this result-array?

thanx


Subject: Re: Simplify an array

From: Jerome Briot

Date: 21 Nov, 2007 09:38:31

Message: 2 of 4

Hi,

try this :

C={1 2
3 4
5 7
6 7
7 8
9 10
10 11}

idx=diff([-inf [C{:,1}]])==1;

C(idx,:)=[]

Jérôme

Subject: Re: Simplify an array

From: Roger Stafford

Date: 21 Nov, 2007 10:11:09

Message: 3 of 4

"Uwe Gallaun" <uwe.gallaun@stud.unileoben.ac.at> wrote in message
<fi0prq$r33$1@fred.mathworks.com>...
> dear matlab users
>
> array=
> [1] [2]
> [3] [4]
> [5] [7]
> [6] [7]
> [7] [8]
> [9] [10]
> [10][11]
> now i'm trying to look if the numbers in the first column
> growing with increment 1.
> as result i want to display this array:
> result=
> [1] [2]
> [3] [4]
> [5] [8]
> [9] [11]
>
> for example:
> three points
> [5] [7]
> [6] [7]
> [7] [8]
> i'm trying to simplify it to get the start and the end:
> [5] [8]
>
> how can i get this result-array?
>
> thanx
-------
  Is this what you want? Call 'a' be the original two-columned array.

 d = diff(a(:,1))~=1;
 r = [a([true;d],1),a([d;true],2)]; % The result

Roger Stafford

Subject: Re: Simplify an array

From: Uwe Gallaun

Date: 21 Nov, 2007 10:30:07

Message: 4 of 4

Jerome Briot <dutmatlab@yahoo.fr> wrote in message
<fi0uam$dlu$1@news.netfinity.fr>...
> Hi,
>
> try this :
>
> C={1 2
> 3 4
> 5 7
> 6 7
> 7 8
> 9 10
> 10 11}
>
> idx=diff([-inf [C{:,1}]])==1;
>
> C(idx,:)=[]
>
> Jérôme


with this code i can just delete those rows that are growing
+1.
if i have the array
    [ 1] [ 2]
    [ 3] [ 4]
    [ 5] [ 7]
    [ 6] [ 7]
    [ 7] [ 8]
    [ 9] [10]
    [10] [11]
i want to find which points belong to each other and write
the end- and startpoints in an array.
thats why i tried it with the growing of 1.
if it is 1 the next point belongs to the least, and if it's
not 0 it doesn't. in the end i should receive this array
    [1] [ 2]
    [3] [ 4]
    [5] [ 8]
    [9] [11]

how can i do that?


Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
array Uwe Gallaun 21 Nov, 2007 03:25:04
simplify Uwe Gallaun 21 Nov, 2007 03:25:04
sort Uwe Gallaun 21 Nov, 2007 03:25:04
rssFeed for this Thread

envelope graphic E-mail this page to a colleague

Public Submission Policy
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.
Related Topics