Probably anyone with programming experience can help me!! Classic List Threaded 5 messages Open this post in threaded view
|

Probably anyone with programming experience can help me!!

 hello I have a little snug! i have a big list with 4 arithmetic variables in 4 columns, the first two are categorical and the two last are x y coordinates so.. i want to plot a new 2D figure for each different value of the first variable and for each figure a new line (plot of x and y) for each different value of the second variable. 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.  thanks a lot
Open this post in threaded view
|

Re: Probably anyone with programming experience can help me!!

 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
Open this post in threaded view
|

Re: Probably anyone with programming experience can help me!!

 thanks for your fast reply!! your suggestion is very clear and very useful, but i have two problems 1) The values of the categorical variables are not fixed 2) There are a lot of them I can not think a way to get a subset of the data for each different combination of the two categorical variables, without knowing them. Because the amount of graphs to be plotted is big, I was hoping for some loop, so I can get a different figure for each value of the first category and plot a different line for each value of the second category, without the need to use certain conditional values for each case. I tried a combination of for and ifs and one with while but I can't set right