Searching and Manipulating Cell Array - Part 2

1 次查看(过去 30 天)
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