How can i automate the following process for n times?

조회 수: 3 (최근 30일)
Riccardo Rossi
Riccardo Rossi 2018년 11월 21일
답변: Guillaume 2018년 11월 21일
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)]

채택된 답변

Guillaume
Guillaume 2018년 11월 21일
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by