GENERATE MATRIX FROM VECTORS
2 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Oleg Komarov
on 28 Mar 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]
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!