Info
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
Rearranging array that represents a tour
조회 수: 1 (최근 30일)
이전 댓글 표시
I have an array 'tour' that is an ordered array of numbers 1,...,n. In addition I have a cell array X in which each element is a position in which to cut the tour, and a cell array Y which contains information on how to rearrange the array.
For example:
tour = 2 7 6 5 4 1 3
X = {[3 4], [1 7], [1 2]};
Y = {[5 2], [3 7], [2 6]};
So the cuts should be as follows: (last element connects to the first) 2 | 7 6 | 5 4 1 3 | Resulting in arrays:
2
7 6
5 4 1 3
And then mending the pieces together according to Y to obtain: 2 5 4 1 3 7 6
How can I implement this, or is there a smarter/more efficient way to go about this?
댓글 수: 2
Adam
2018년 10월 5일
X would seem to be a lot more simply encoded as a single index. whether the one immediately before the cut or immediately after doesn't really matter, your pairs in X will always be consecutive (with wrapping) I assume.
also, if you could then encode Y as just an ordering of the parts from X rather than the components therein that would be a lot easier. i.e. Y would just be a permutation whose length is equal to the number of sections you end up with from your cuts in X. In a general case this would usually be numel(X) + 1, though in the specific example you give it is just numel(X) as an edge case.
답변 (0개)
이 질문은 마감되었습니다.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!