Using a function in a 'for' loop?

조회 수: 5 (최근 30일)
TerribleAtCoding
TerribleAtCoding 2017년 9월 10일
답변: Walter Roberson 2017년 9월 10일
My function must take a specified path through an array from one end to the other given a starting position.
For my function, I would like to get two outputs:
1) a 1D array of the row indices of the path
2) a 1D array of the column indices of the path
Is it possible to use a 'for' loop that calls to another function (this function will select the coordinates of the next position, and the next, etc.)? And how would I go about storing the indices to get my output?
  댓글 수: 2
KSSV
KSSV 2017년 9월 10일
What array you have? What path? Explain your purpose.
TerribleAtCoding
TerribleAtCoding 2017년 9월 10일
편집: TerribleAtCoding 2017년 9월 10일
The array is just a random set of integers. The path's purpose is to pick a number in the adjacent column that is closest to the current number (the function I am trying to use in the loop picks this). This should repeat until I get from one end of the array to the other, then the output should be individual arrays of the row and column indices of the path taken.

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

채택된 답변

Walter Roberson
Walter Roberson 2017년 9월 10일
row(1) = 1; col(1) = 1;
for K = 2 : 10
[row(K), col(K)] = calculate_next_step(row(K-1), col(K-1));
end

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by