On Fri, Feb 17, 2012 at 5:24 PM, athan <

[hidden email]> wrote:

> i know how to plot lines point etc.

> but i am searching a convenient way to separate the data for each line to be

> plotted

> this is probably something quite simple but my programming skills are not

> quite there.

One way to do this is to use a boolean vector to index your data

matrix. Example:

This is a matrix that's similar to what you describe:

octave:1> X = [ 1 1 1.1 2.1 ; 1 2 1.2 4.3 ; 2 1 1.3 5.2 ; 2 1 0.9 1.0

; 1 2 7.5 -9.1]

X =

1.00000 1.00000 1.10000 2.10000

1.00000 2.00000 1.20000 4.30000

2.00000 1.00000 1.30000 5.20000

2.00000 1.00000 0.90000 1.00000

1.00000 2.00000 7.50000 -9.10000

One simple way to do this is to extract the two categorical columns as vectors:

octave:2> c1 = X(:,1) # 1st column

c1 =

1

1

2

2

1

octave:3> c2 = X(:,2) # 2nd column

c2 =

1

2

1

1

2

Then if you do a boolean operation like:

octave:4> c2 == 1

ans =

1

0

1

1

0

You end up with a boolean vector with 1 (i.e. true) wherever the

second column equals 1 and 0 (i.e. false) everywhere else. You can use

boolean vectors to index. When you do this you get a matrix that

includes the true rows and excludes the false rows. For example:

octave:5> X(c2==1,:)

ans =

1.00000 1.00000 1.10000 2.10000

2.00000 1.00000 1.30000 5.20000

2.00000 1.00000 0.90000 1.00000

gives you all the rows of X where the second column is 1 and

octave:6> X(c1==2 & c2==1, :)

ans =

2.00000 1.00000 1.30000 5.20000

2.00000 1.00000 0.90000 1.00000

gives all the rows where the first column is 2 and the second column is 1.

As always, depending on exactly how big your data table is and whether

or not it has some sort of structure special structure, there may be

much more efficient or faster ways to do this.

--judd

_______________________________________________

Help-octave mailing list

[hidden email]
https://mailman.cae.wisc.edu/listinfo/help-octave