I'm going to assume at least one of the swap elements must be an number, and that the swapped numbers are allowed to have the same value (so you can some one 9 with another 9).
C= [1 6 5 10 1 2 11 8 2 7 3 7 9 9];
bold=[1 5 6 9 10 12 13 14];
C_temp=cell(1,2*numel(C));
C_temp(2:2:end)=num2cell(C);
valid_idx=1:numel(C_temp);
valid_idx(bold*2)=[];
swap_idx=[1 1];
while ~any(mod(swap_idx,2)==0) || ...
swap_idx(1)==swap_idx(2)
swap_idx=valid_idx(randperm(numel(valid_idx),2));
end
C_temp(swap_idx)=C_temp(swap_idx(end:-1:1));
D=cell2mat(C_temp);
clc,disp(C),disp(D)
Best Answer