find corresponding elements in a vector
이전 댓글 표시
Hello everyone! Let's assume we have the vectors U and V:
U=[6 6 18 18 3 19 12 18 24 24 10 22 11 27 28 18 12 12];
V=[5 7 10 10 21 2 21 10 23 7 1 13 2 19 10 1 13 21];
The length of the vectors usually ranges from 9 to 20. We are trying to correspond each element of U to one element in V which satisfies certain conditions. For example, the right answer satisfies either U(j) = V(i) + abs(i-j) or U(j) = V(i) - abs(i-j)
The problem is using perms for length>9 goes to memory error. Any help is appreciated. I am running on a 32Bit. Thanks!
댓글 수: 5
KSSV
2017년 5월 29일
Give the complete code, which lead to error..
Ali
2017년 5월 29일
Walter Roberson
2017년 5월 29일
"We are trying to correspond each element of U to one element in V which satisfies certain conditions."
U(2) = V(1) + abs(1-2) %6 = 5 + abs(-1)
U(2) = V(6) + abs(2-6) %6 = 2 + abs(-4)
So, are we to choose the first of the solutions, or the last, or any one which is convenient ?
KSSV
2017년 5월 29일
perms(1:10) is giving you a matrix of size 3628800*10, this number is huge for your memory...so error popped. Is it necessary to generate such huge matrix?
Ali
2017년 5월 29일
채택된 답변
추가 답변 (1개)
Walter Roberson
2017년 5월 29일
In R2016b or later, you can express the search as
matches = ~(U.' -V + abs((1:18) .' - (1:18))) | ~(U.' -V - abs((1:18) .' - (1:18)));
This will give you a binary array of matches. For example the first row is
0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0
reflecting that U(1) and V(2) are in the right relationship and U(1) and V(14) are in the right relationship.
You posted that "The point is the conditions are satisfied only for one unique set." but with those U and V values, there are no matches for U([3 11 12 13 14 15]) or for V([3 4 10 11 13 16 18])
댓글 수: 3
Ali
2017년 5월 29일
Walter Roberson
2017년 5월 29일
Your variable POOL does not appear to occur in your original question in any form.
Ali
2017년 5월 29일
카테고리
도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!