help-octave
[Top][All Lists]
Advanced

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

Re: Combining Vectors


From: GFotios
Subject: Re: Combining Vectors
Date: Mon, 18 Apr 2011 11:23:22 +0200


On Apr 18, 2011, at 11:11 AM, stn wrote:


Hi,

is there a function that will combine two vectors so that the result has two columns and one row for each possible combination of the elements of the two vectors?

like this:
a = [1 ; 2 ; 3]
b = [4 ; 5 ; 6]

combined_vectors = [
1 4
1 5
1 6
2 4
2 5
2 6
3 4
3 5
3 6
 ]

THX
stn
_______________________________________________
Help-octave mailing list
address@hidden
https://mailman.cae.wisc.edu/listinfo/help-octave


[v1,v2] = meshgrid ([1;2;3],[4;5;6])

and then

[v1(:),v2(:)]

is what you want. Or

v1 = repmat([1;2;3],1,3).'(:)
v2 = repmat([4;5;6],1,3)(:)
[v1, v2]

Enjoy,
/Fotis


reply via email to

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