MATLAB: Swapping entries in column of table

MATLABswaptable

I've the following table and I want to swap the entries
tbl = table({'1', '2'; '2', '3'; '2', '3'; '3', '4'},'VariableNames', {'multicol'});
i_pts = 2;
for i = i_pts
searchval = num2str(i);
temp_tbl = tbl(any(strcmp(tbl.multicol, searchval), 2), :);
end
temp_tbl
Obtained output:
multicol
______________
{'1'} {'2'}
{'2'} {'3'}
{'2'} {'3'}
I'd like to obtain the following from the above output.
multicol
______________
{'2'} {'1'}
{'2'} {'3'}
{'2'} {'3'}
Any suggestion on how on this can be done?

Best Answer

I'm not sure why you're using string characters instead of numbers but I'll assume you have a reason for that. Here's how to identify the rows of tbl.multicol where the second column contains the character representation of i_pts (which is numeric). Then flip those rows.
rowsToSwitch = strcmp(tbl.multicol(:,2),num2str(i_pts)); %logical vector identifying rows to flip
tbl.multicol(rowsToSwitch,:) = fliplr(tbl.multicol(rowsToSwitch,:)); % Flip those rows