help-octave
[Top][All Lists]

## Re: Combining Vectors

 From: stn Subject: Re: Combining Vectors Date: Mon, 18 Apr 2011 23:48:50 +0200

2011/4/18 GFotios

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

[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

Yes, thank you.
Both methods work. With meshgrid it is even possible to combine 3 vectors:

[v1,v2,v3] = meshgrid ([1;2;3],[4;5;6],[7 8 9]) ;
[v1(:),v2(:),v3(:)]

Can this also be done with an abitrary number of vectors ?
The idea is to generate input-data for a simulation which is supposed to run an existing model with every conceivable combination of input-data. It would then calculate statistics, distribution etc. The number of input-variables is 6 to 8, with 5 values per variable.

Incidentally: does this operation have a mathematical name and symbolic representation?

This is of course equivalent to 6 to 8 nested loops, with the innermost loop executing the model. Unfortunately AFAIK there is no way to change the nesting-level and the loop-variables without changing the code.

So what I am actually looking for is some kind of universal parameter-controlled nested loop. The idea with multiple combined matrices is just one possible solution.

THX
stn