[sortedA, idx] = sort( a );
sortedB = b(idx);
When you look at something like
which, by the way, is the obvious first place to search when you want to do something like this, always take note of all the different calling syntaxes for a function. So many questions are asked that turn out to just be a case of someone not looking far enough down the help page.
In particular, in cases like this, take note of all the output arguments, not just the first. Functions like sort (and unique and various others that change an array in some way or other) usually also return a set of indices that can be applied to another vector to achieve the same sorting (or whatever shuffling of the elements of the array took place).