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!