Searching and Manipulating Cell Array - Part 2

조회 수: 3 (최근 30일)
Sam Da
Sam Da 2012년 10월 19일
This is a new problem but the problem data is similar.
I have a cell array A:
[3,2]
[2,4]
[4,5]
[2,5]
[6]
and cell array B:
[2,3,4]
[2,6]
[4,5,6]
In the array B I can see that [2,3,4] is made of elements from [3,2] and [2,4] from A. So, I will assign these two elements from A to B and remove them from A.
A now has:
[4,5]
[2,5]
[6]
[2,5] in B is made from elements of [4,5] and [2,5] from A. So, we assign [4,5] and [2,5] to second element of B and so on. Please observe in second example that 4 was an extra element from A which was not present in B at all but still I want to assign [4,5] and [2,5] to second element of B. We delete them from A.
Now A has only:
[6]
So, how do I achieve this?
Thanks guys
  댓글 수: 2
Matt J
Matt J 2012년 10월 20일
편집: Matt J 2012년 10월 20일
Quote: "[2,5] in B is made from elements of [4,5] and [2,5] from A."
B as you've listed it does not show a [2,5]. It does show a [2,6]
Also, even if B did include [2,5], it wouldn't require elements from [4,5] in A since the [2,5] in A completely covers the [2,5] in B.
Matt J
Matt J 2012년 10월 20일
Quote: "Please observe in second example that 4 was an extra element from A"
If extra elements don't matter, why not use all of A to cover B{1}. Also, what if there are multiple different ways to cover a B{i} with members of A? Does it matter which one we pick?

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

채택된 답변

Matt J
Matt J 2012년 10월 20일
편집: Matt J 2012년 10월 20일
This shouldn't require very much change to the solution I gave you in Part 1
In the outer loop over B, you can delete things from A. Better yet, instead of deleting, overwrite the appropriate A{i} with nans to avoid a lot of memory reallocation.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by