How can i automate the following process for n times?

3 visualizaciones (últimos 30 días)
Riccardo Rossi
Riccardo Rossi el 21 de Nov. de 2018
Respondida: Guillaume el 21 de Nov. de 2018
Hi everyone, how can i automate the following process for n times?
Thank you so much!
r=0.002
POINT1= [X, Y, Z];
POINT2= [POINT1(:,1), POINT1(:,2), r+POINT1(:,3)];
POINT3= [POINT2(:,1), POINT2(:,2), r+POINT2(:,3)];
POINTn= [POINTn-1(:,1), POINTn-1(:,2), r+POINTn-1(:,3)]

Respuesta aceptada

Guillaume
Guillaume el 21 de Nov. de 2018
Never create numbered variables. It's a clear indication that you should be using an array, which can be easily indexed instead.
r = 0.002;
X = [0;1;2]; Y = [0;2;4]; Z = [0;-1;1];
n = 5;
Point = [X, Y, Z] + [0, 0, 1] .* (permute(0:n-1, [1, 3, 2]) * r)
Your is now Point(:, :, i).
The above is just one of many ways of generating that 3d matrix.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by