MATLAB: How to change multiple elements in a character array at once

character arrayMATLAB

Letters = 'vegetables' Hi, I was trying to change the 5th element of the character arrays to the letter X and the last element to the letter Z in one short command. So the final answer will be : Letters = 'vegeXableZ' How can I do it?

Best Answer

Just use indexing:
Letters([5,end]) = 'XZ'