how to change multiple elements in a character array at once

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 日

1 投票

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

その他の回答 (1 件)

GK
GK 2018 年 9 月 4 日

0 投票

You can simply use,
Letters(5)='X';
Letters(end)='Z';

カテゴリ

製品

リリース

R2018a

質問済み:

2018 年 9 月 4 日

回答済み:

GK
2018 年 9 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by