how to store a value in the next row?

2 ビュー (過去 30 日間)
VENGATESAN S
VENGATESAN S 2020 年 9 月 3 日
編集済み: Stephen23 2020 年 9 月 4 日
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 Center および File ExchangeGet Started with MATLAB についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by