如果A
是一个矩阵,其第二列(A(:,2)
)代表不同"categories"
的标签:
A =
{ 3x2 cell} [ 1]
{ 2x2 cell} [ 2]
{ 3x2 cell} [ 3]
{ 4x2 cell} [ 4]
并且每个"category"
都包含一些"numbers"
,其分类为"sub-categories"
。这意味着A{i}(:,2)
是"sub-categories"
的标签。例如:
%copy-paste A into MATALB
A{1} = {[2.5] [1]; % sub-category is [A]
[1.49] [2]; % sub-category is [B]
[0.35] [3]}; % sub-category is [C]
A{2} = {[3.8] [1]; % sub-category is [A]
[1.09] [2]}; % sub-category is [B]
A{3} = {[6.95] [1]; % sub-category is [A]
[7.04] [2]; % sub-category is [B]
[2.85] [3]}; % sub-category is [C]
A{4} = {[5.5] [1]; % sub-category is [A]
[3.1] [2]; % sub-category is [B]
[6.76] [3]; % sub-category is [C]
[9.8] [4]}; % sub-category is [D]
A=A.'
A{1,2}=1;
A{2,2}=2;
A{3,2}=3;
A{4,2}=4
目标(B
)是根据"numbers"
标签(A)对"sub-category"
(2.5,1.49等)进行分类,B,C和D)。此外,最重要的一点是,只应对那些彼此相邻的"sub-categories"
进行分类。这意味着,应该在同一个组"numbers"
中选择"sub-category"
,并且只在下一个和上一个"categories"
(1,2,3和4)中搜索它们)即可。因此,在我们的示例中,我们希望得到:
% First column shows the number
% Second column shows the sub-category
% Third column shows the category
% For [2.5] which has sub-category "A" or better to say "[1]",
% it has only one neighborhood in category [2]:
B{1}=
[2.5] [1] [1]
[3.8] [1] [2]
% For [1.49] which has sub-category "B" or it is better to say "[2]",
% it has also one neighborhood in category [2]:
B{2}=
[1.49] [2] [1]
[1.09] [2] [2]
% For [2.5] which has sub-category "A" or it is better to say "[1]",
% it has two neighborhood in category [2] & [3]:
B{3}=
[2.5] [1] [1]
[3.8] [1] [2]
[6.95] [1] [3]
% For [1.49] which has sub-category "B" or it is better to say "[2]",
% it has two neighborhood in category [2] & [3]:
B{4}=
[1.49] [2] [1]
[1.09] [2] [2]
[7.04] [2] [3]
% For [2.85] which has sub-category "C" or it is better to say "[3]",
% it has one neighborhood in category [4]:
B{5}=
[2.85] [3] [3]
[6.76] [3] [4]
% For [6.95] which has sub-category "A" or it is better to say "[1]",
% it has two neighborhood in category [2] & [4]:
B{6}=
[6.95] [1] [3]
[3.8] [1] [2]
[5.5] [1] [4]
% For [5.5] which has sub-category "A" or it is better to say "[1]",
% it has one neighborhood in category [3]:
B{7}=
[5.5] [1] [4]
[6.95] [1] [3]
% For [9.8] which has sub-category "D" or it is better to say "[4]",
% there is no number with the same label:
B{8}=
[9.8] [4] [4]
% And finally, for [0.35]; although, there are some number with the same label,
% there is no neighborhood in the next category( means category 2):
B{9}=
[0.35] [3] [1]
为了澄清问题,我被要求添加一些解释。因此,首先,我们应该搜索每个数字的"sub-category"
标签。然后,在具有相同标签的那些数字中,我们需要检查他们是否在下一个或后一个"category"
中具有相同"sub-category"
的邻居。
如果正确的代码可能用cellfun
或bsxfun
函数编写而不是使用循环,那将是很好的,因为它可能更有效。感谢