how to store a value in the next row?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Stephen23
el 3 de Sept. de 2020
Editada: Stephen23
el 3 de Sept. de 2020
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 comentarios
Stephen23
el 4 de Sept. de 2020
Editada: Stephen23
el 4 de Sept. de 2020
"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.
>>
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!