how to store a value in the next row?
조회 수: 6 (최근 30일)
이전 댓글 표시
i want to extract the coordinates for a squar plate having length of 1m. i want to divide into 25 smaller square whose lenth is 0.2. so that i will get an array of (25,2).
x1=0; x2=1;
y1=0; y2=1;
del=0.2;
step=zeros(25,2);
for y=y1:del:y2;
for x=x1:del:x2;
step=[x y]
end
end
what i am getting from this program is
step =
0 0
step =
0.2000 0
step =
.4000 0
step =
0.6000 0
.............................
step =
1 1
what im actually want is
step= 0 0
0 0.2
0 0.4
. .
. .
1 1
i want to store the value in the next row for the next loop.
댓글 수: 0
답변 (1개)
Stephen23
2020년 9월 3일
편집: Stephen23
2020년 9월 3일
The MATLAB approach:
>> [X,Y] = ndgrid(0:0.2:1);
>> M = [Y(:),X(:)]
M =
0.00000 0.00000
0.00000 0.20000
0.00000 0.40000
0.00000 0.60000
0.00000 0.80000
0.00000 1.00000
0.20000 0.00000
0.20000 0.20000
0.20000 0.40000
0.20000 0.60000
0.20000 0.80000
0.20000 1.00000
0.40000 0.00000
0.40000 0.20000
0.40000 0.40000
0.40000 0.60000
0.40000 0.80000
0.40000 1.00000
0.60000 0.00000
0.60000 0.20000
0.60000 0.40000
0.60000 0.60000
0.60000 0.80000
0.60000 1.00000
0.80000 0.00000
0.80000 0.20000
0.80000 0.40000
0.80000 0.60000
0.80000 0.80000
0.80000 1.00000
1.00000 0.00000
1.00000 0.20000
1.00000 0.40000
1.00000 0.60000
1.00000 0.80000
1.00000 1.00000
댓글 수: 3
Stephen23
2020년 9월 4일
편집: Stephen23
2020년 9월 4일
"but it shows ...Error: Invalid use of operator."
Lets have a look:
>> [X,Y] = ndgrid(0:0.2:1);
>> M = [Y(:),X(:)] % my code (no spaces, no error)
M =
0 0
0 0.2000
... more lines here
1.0000 0.6000
1.0000 0.8000
1.0000 1.0000
>> M = [Y (:),X (:)] % your code (add spaces -> error)
M = [Y (:),X (:)]
↑
Error: Unexpected MATLAB operator.
>>
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!