how to change multiple elements in a character array at once

13 次查看(过去 30 天)
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?

采纳的回答

Stephen23
Stephen23 2018-9-4
编辑:Stephen23 2018-9-4
Just use indexing:
Letters([5,end]) = 'XZ'

更多回答(1 个)

GK
GK 2018-9-4
You can simply use,
Letters(5)='X';
Letters(end)='Z';

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by