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
0 件のコメント
採用された回答
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]
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!