Standard, idiomatic way :
Use the index vector:
arr([ij]) = arr([ji]); %// arr can be any array type
This works if arr is an array of cells, a numeric array, or a string (char array).
Not recommended (but possible):
If you want to use a syntax that is more similar to the syntax in Python (with a list of elements instead of an index vector), you will need a deal . But the resulting statement is more complex and varies depending on whether arr a cell array or a standard array. Therefore, it is not recommended (for the exchange of two elements). I include it for completeness only:
[arr{i}, arr{j}] = deal(arr{j}, arr{i}); %// for a cell array [arr(i), arr(j)] = deal(arr(j), arr(i)); %// for a numeric or char array
source share