필터 지우기
필터 지우기

Loop Fuction to keep adding 1

조회 수: 1 (최근 30일)
Aldo Hernandez
Aldo Hernandez 2019년 11월 26일
편집: Turlough Hughes 2019년 11월 26일
I want to write a function that will continously keep adding adding 1 to a coordinate.
Say we have a matrix point [X,Y]. I want to keep adding 1 to the Y component of the point until a set ending and have all of these set as different points.
For example, say we have [X,Y] and we want to stop at [X,Y+3]. I want to have a set of points that at the end looks like:
[X,Y],[X,Y+1],[X,Y+2],[X,Y+3]
I apologize if this isnt clear. I have no experience with loop functions and also do not know how to terminate them at a given point.

채택된 답변

Turlough Hughes
Turlough Hughes 2019년 11월 26일
편집: Turlough Hughes 2019년 11월 26일
You shouldn't need to write a function for this. I would just define your first x and y, and then n being the length:
x1=1; y1=4; n=20; %nominally selected values
Your answer would then be:
x=x1.*ones(1,n);
y=y1:y1+n-1;

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by