how to store a value in the next row?
3 次查看(过去 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.
>>
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!