MATLAB: How do i compare cell array values and replace with string of code letters

cell arrays

% If i have a cell array like, cellArr = {'UUU'} {'CUU'} {'UUC'} {'UUG'} i
% want to create a string with appropriate code as per below eg 'FLFL'
F = {'UUU','UUC'};
L = {'UUA','UUG','CUU','CUC','CUA','CUG'};
% empty string.
amino_acid_chain = strings(1,numel(cellArr));
for i = 1:numel(cellArr)
amino_acid_chain(i) = strcmpi(cellArr(i), 'UUU');
end
The best i can come up with at the moment is to create an empty string array, then use strcmpi (to ignore case), and find a way to replace true entries with appropriate code. Two problems, 1st, i dont know how to compare {'UUU', 'UUC'} instead of just 'UUU', and 2nd, how do i convert true entries to code (F or L). Alternatively, im sure theres probably a much easier way to achieve this so any other advice would be appreciated.

Best Answer

Method one:
>> C = {'UUU','CUU','UUC','UUG'};
>> F = {'UUU','UUC'};
>> L = {'UUA','UUG','CUU','CUC','CUA','CUG'};
>> Xf = ismember(C,F)
Xf =
1 0 1 0
>> Xl = ismember(C,L)
Xl =
0 1 0 1
And then use indexing:
>> Y = Xf+2*Xl
Y =
1 2 1 2
>> Z = 'FL';
>> Z(Y)
ans = FLFL
Or even something like:
>> char('F'*Xf + 'L'*Xl)
ans = FLFL
Use upper on ismember's input arguments to get case-insensitive comparisons.
Method two:
>> [~,X] = ismember(C,[F,L]);
>> V = cumsum(cellfun(@numel,{F,L}));
>> Y = 1+sum(V(:)<X)
Y =
1 2 1 2
Method three:
>> C = {'UUU','CUU','UUC','UUG'};
>> F = {'UUU','UUC'};
>> L = {'UUA','UUG','CUU','CUC','CUA','CUG'};
>> F(2,:) = {'F'};
>> L(2,:) = {'L'};
>> D = [F,L];
>> [~,X] = ismember(C,D(1,:));
>> [D{2,X}]
ans = FLFL