how to change multiple elements in a character array at once

20 Ansichten (letzte 30 Tage)
Rachel Barbera
Rachel Barbera am 4 Sep. 2018
Beantwortet: GK am 4 Sep. 2018
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?

Akzeptierte Antwort

Stephen23
Stephen23 am 4 Sep. 2018
Bearbeitet: Stephen23 am 4 Sep. 2018
Just use indexing:
Letters([5,end]) = 'XZ'

Weitere Antworten (1)

GK
GK am 4 Sep. 2018
You can simply use,
Letters(5)='X';
Letters(end)='Z';

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Produkte


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by