如果我有一个 4x1 Cell 结构,它代表a=[A1 A2 A3 A4]
:
a=cell(4,1)
a{1}=[1 3 1 0]
a{2}=[3 3 3 3]
a{3}=[3 2 3 2]
a{4}=[3 3 3 2]
B=[1 1 1 2]; %priority
我想做以下事情:
选择与优先级相对应的单元格B=[1 1 1 2]
(where B=1
是最高优先级并且A=3
)
这意味着,找到以 [3 3 3 #] 开头的任何单元格,其中所有优先级均为 1B
.
理想的答案应该是:a{2}
=[3 3 3 3]
and a{4}
= [3,3,3,2]
我的尝试是添加这个:
[P arrayind]=min(B) % problem is that arrayind return index=1 only .. not all indices
if P==1
arrayindex = 1:4 ; %look at each index of the array
c = a(cellfun(@(x) ismember(x(arrayindex), 3), a));
end
然而,这给了我一个错误,指出:
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
通过调整代码来适应此错误:
c = a(cellfun(@(x) ismember(x(arrayindex), 3), a,'UniformOutput',false));
I get this error :
Error using subsindex
Function 'subsindex' is not defined for values of class 'cell'.
现在我被困在这一点上。