help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


From: Judd Storrs
Subject: Re: Probably anyone with programming experience can help me!!
Date: Sat, 18 Feb 2012 02:38:51 -0500

On Sat, Feb 18, 2012 at 1:30 AM, athan <address@hidden> wrote:
> 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.

I think you probably want the unique() function.

octave:10> unique(c1)
ans =

   1
   2

octave:11> unique(c2(c1==1))
ans =

   1
   2

octave:12> unique(c2(c1==2))
ans =  1

octave:13> for i=unique(c1)'  # note the ' -- need values as a row
>    for j=unique(c2(c1==i))'
>       X(c1==i & c2==j, :)
>    endfor
> endfor
ans =

   1.0000   1.0000   1.1000   2.1000

ans =

   1.0000   2.0000   1.2000   4.3000
   1.0000   2.0000   7.5000  -9.1000

ans =

   2.00000   1.00000   1.30000   5.20000
   2.00000   1.00000   0.90000   1.00000

This is probably an improvement:

octave:14> for i=unique(c1)'
>    X2 = X(c1==i,:);
>    c2 = X2(:,2);
>    for j=unique(c2)'
>       X2(c2==j,:)
>    endfor
> endfor
ans =

   1.0000   1.0000   1.1000   2.1000

ans =

   1.0000   2.0000   1.2000   4.3000
   1.0000   2.0000   7.5000  -9.1000

ans =

   2.00000   1.00000   1.30000   5.20000
   2.00000   1.00000   0.90000   1.00000


--judd


reply via email to

[Prev in Thread] Current Thread [Next in Thread]