Thanks to Peter's comment, I investigated the command line options.
An automatic way of doing what I need is:
version = mexext;
if (version(5) == '3') % this is 32bit
% include 32bit version code
elseif (version(5) == '6') % this is 64bit
% include 64bit version code
else
% deal with problems (should never occour)
end
the mex
command(s) will have to include the option -f $full_path_to_correct_mexopts.bat