GENERATE MATRIX FROM VECTORS

2 visualizaciones (últimos 30 días)
Emerson De Souza
Emerson De Souza el 28 de Mzo. de 2011
I want to generate a matrix M of TWO columns and J rows.
An initial value (=XSTART) is fixed for the first column
while the second column runs from a value
YSTART in increments K until a final value YEND .
Then an increment L is added to XSTART
and the second column runs again from
YSTART in increments K until a final value YEND.
The increment L stops if the value of X equals XEND.
For example, let
1) X runs in increment of 4 from 0 until 12 (XSTART=0, L=4, XEND=8)
The vector components are (0, 4, 8)
2) Y runs in increment of 5 from 0 until 15 (YSTART=0, K=5, YEND=15)
The vector components are (0, 5, 10, 15)
The resulting matrix should be
0 0
0 5
0 10
0 15
4 0
4 5
4 10
4 15
8 0
8 5
8 10
8 15
I hope someone know the correct syntax
and help me to write a command that generates
this matrix for given set of initial and end values
for x and y and their respective increments.
Thank you a lot
Emerson

Respuesta aceptada

Oleg Komarov
Oleg Komarov el 28 de Mzo. de 2011
x = 0:4:8;
y = 0:5:15;
numX = numel(x);
numY = numel(y);
y = repmat(y(:),numX,1);
x = repmat(x ,numY,1);
out = [x(:) y]
  1 comentario
Emerson De Souza
Emerson De Souza el 28 de Mzo. de 2011
Dear Oleg,
thank you a lot for your help!
I got exactly what I needed
by following your suggestion.
I wish you a nice day
Emerson

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by