If I have a 4x1 Cell structure with that represents 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
I would like to do the following :
Pick cells that correspond to priority B=[1 1 1 2] (where B=1 is highest priority and A=3)
Which means, find any cell that begins with [3 3 3 #], where all their priority is 1's in B.
ideal answer should be : a{2}=[3 3 3 3] and a{4} = [3,3,3,2]
My try is to add this :
[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
However this gives me an error stating :
Error using cellfun
Non-scalar in Uniform output, at index 1, output 1.
Set 'UniformOutput' to false.
By adjusting the code to accommodate this error :
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'.
And now I'm stuck at this point.
cellfunline according to the error? that iscellfun(@(x) ... ,'UniformOutput', false);a{2}anda{4}[val ind] = max(cellfun(@(x) length(find(ismember(x(arrayindex), 3))), a)); b = a(ind);. This will give the cell array with the highest number of 3s.