필터 지우기
필터 지우기

A for loop that allows me to increase by 2 terms of a vector

조회 수: 2 (최근 30일)
Marco Camozzi
Marco Camozzi 2020년 7월 3일
답변: Vashist Hegde 2020년 7월 3일
Hello everyone!
someone could help me to find a loop for that allows me, for a vector of n terms, to perform the following action "coord1 = XY(Edge(i,1),:);" on the first term and the same action on the term n+2?
at the moment I can only increase by one term with the following code.
Thank you!
XY = [0 0;
5 0;
5 -5];
Edge = [1 2;
2 3];
EdgeL = [ 5;
5];
for i = 1 : size(XY,1)
coord1 = XY(Edge(i,1),:);
coord3 = XY(Edge(i,2),:);
end
  댓글 수: 1
KALYAN ACHARJYA
KALYAN ACHARJYA 2020년 7월 3일
Here the inputs,
XY = [0 0;
5 0;
5 -5];
Edge = [1 2;
2 3];
Now what would be the desired output/logic?

댓글을 달려면 로그인하십시오.

채택된 답변

Vashist Hegde
Vashist Hegde 2020년 7월 3일
you can use the for loop this way -
for i = 1 :2: size(XY,1)
coord1 = XY(Edge(i,1),:);
coord3 = XY(Edge(i,2),:);
end
This will run the loop on alternate terms.

추가 답변 (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