MATLAB: How to do multiple replacements in a cell array

MATLAB

Hi,
I am wondering what is the most efficient way in Matlab to do multiple replacements in a cell array based on the content of a differentt cell array ?
More specifically, I am trying to transform cell1 into cell3 based on the associations defined in cell2 in the most efficient way possible (in other words cell1(:,2) becomes cell3(:,2))
% Cell array data
cell1 = {1, 2, 3, 4, 5; 'A', 'A', 'B', 'C', 'B'; 'AA', 'BB', 'CC', 'DD', 'JJ'}'
% Cell array reference
cell2 = {'C', 'B', 'A'; 'FFFF', 'GGGG', 'HHHH'}'
% Desired output
cell3 = {1, 2, 3, 4, 5; 'HHHH', 'HHHH', 'GGGG', 'FFFF', 'GGGG'; 'AA', 'BB', 'CC', 'DD', 'JJ'}'
Thank you,

Best Answer

>> [idx,idy] = ismember(cell1(:,2),cell2(:,1));
>> cell3 = cell1;
>> cell3(idx,2) = cell2(idy(idx),2)