how to change multiple elements in a character array at once

19 visualizaciones (últimos 30 días)
Rachel Barbera
Rachel Barbera el 4 de Sept. de 2018
Respondida: GK el 4 de Sept. de 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?

Respuesta aceptada

Stephen23
Stephen23 el 4 de Sept. de 2018
Editada: Stephen23 el 4 de Sept. de 2018
Just use indexing:
Letters([5,end]) = 'XZ'

Más respuestas (1)

GK
GK el 4 de Sept. de 2018
You can simply use,
Letters(5)='X';
Letters(end)='Z';

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by