Hi,

Thank you for your help.

this function 'combvec '  takes any number of inputs on Matlab. So, you can
 take more than two matrix.


The help of this function 'combvec' is like this on Matlab:

>> help combvec

 COMBVEC Create all combinations of vectors.

   Syntax

     combvec(a1,a2,...)

   Description

     COMBVEC(A1,A2,...) takes any number of inputs,
       A1 - Matrix of N1 (column) vectors.
       A2 - Matrix of N2 (column) vectors.
     and returns a matrix of (N1*N2*...) column vectors, where the columns
     consist of all possibilities of A2 vectors, appended to
     A1 vectors, etc.

   Example

     a1 = [1 2 3; 4 5 6];
     a2 = [7 8; 9 10];
     a3 = combvec(a1,a2)

2010/4/19 Dennis Murphy <djmu...@gmail.com>

> Hi:
>
> This is a simplistic version of combvec that works for two input matrices;
> I don't
> have Matlab, and I don't understand how the function generalizes to more
> than
> two input matrices, so this is the best I can offer, for what it's worth...
>
> combvec2 <- function(m1, m2) {
>    c1 <- ncol(m1)
>    c2 <- ncol(m2)
>    k1 <- kronecker(matrix(rep(1, c2), nrow = 1), m1)
>    k2 <- kronecker(m2, matrix(rep(1, c1), nrow = 1))
>    rbind(k1, k2)
>   }
>
> > a1 <- matrix(1:6, nrow = 2, byrow = TRUE)
> > a1
>      [,1] [,2] [,3]
> [1,]    1    2    3
> [2,]    4    5    6
> > a2 <- matrix(7:10, nrow = 2, byrow = TRUE)
>
> > combvec2(a1, a2)
>      [,1] [,2] [,3] [,4] [,5] [,6]
> [1,]    1    2    3    1    2    3
> [2,]    4    5    6    4    5    6
> [3,]    7    7    7    8    8    8
> [4,]    9    9    9   10   10   10
>
> HTH,
> Dennis
>
> On Sun, Apr 18, 2010 at 3:00 AM, anderson nuel <anderson....@gmail.com>wrote:
>
>> Hello,
>>
>>  I would like to create all combinations of vectors. I find on Matalb
>> this
>> function 'combvec' which create  all combinations of vectors.
>>
>> Please could you help me to find the corresponds function of 'combvec'.
>>
>> For example:
>>
>> On Matlab
>>
>> >> a1 = [1 2 3; 4 5 6]
>>
>> a1 =
>>
>>     1     2     3
>>     4     5     6
>>
>> >> a2 = [7 8; 9 10]
>>
>> a2 =
>>
>>     7     8
>>     9    10
>>
>> >> a3 = combvec(a1,a2)
>>
>> a3 =
>>
>>     1     2     3     1     2     3
>>     4     5     6     4     5     6
>>     7     7     7     8     8     8
>>     9     9     9    10    10    10
>>
>> Best Regards
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to