How can I access char elements from the beginning up to some fixed index of the char?

2 visualizaciones (últimos 30 días)
a = char(abdefghijk);
I want the output 'abcdefg'

Respuesta aceptada

Walter Roberson
Walter Roberson el 7 de Dic. de 2022

Más respuestas (2)

Vikram Ojha
Vikram Ojha el 7 de Dic. de 2022
Editada: Vikram Ojha el 7 de Dic. de 2022
>> a='abcdefghijk'
>> a(1:5)
ans =
'abcde'
In genral a(1:n) % n for index
You can consider going through following doc: https://in.mathworks.com/help/matlab/ref/string.html, it will be helpful
In case you want you can take Matlab fundamental certification: https://matlabacademy.mathworks.com/details/matlab-fundamentals/mlbe

Steven Lord
Steven Lord el 7 de Dic. de 2022
The extractBefore function will work both for char arrays and strings.

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by