How can i automate the following process for n times?

3 views (last 30 days)
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)]

Accepted Answer

Guillaume
Guillaume on 21 Nov 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.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!