GENERATE MATRIX FROM VECTORS

2 次查看(过去 30 天)
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

采纳的回答

Oleg Komarov
Oleg Komarov 2011-3-28
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 个评论
Emerson De Souza
Emerson De Souza 2011-3-28
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by