how to store a value in the next row?

2 次查看(过去 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.

回答(1 个)

Stephen23
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
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.
>>
VENGATESAN S
VENGATESAN S 2020-9-4
thanks for your support..now it is working

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by