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

1 次查看(过去 30 天)
a = char(abdefghijk);
I want the output 'abcdefg'

采纳的回答

Walter Roberson
Walter Roberson 2022-12-7

更多回答(2 个)

Vikram Ojha
Vikram Ojha 2022-12-7
编辑:Vikram Ojha 2022-12-7
>> 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 2022-12-7
The extractBefore function will work both for char arrays and strings.

类别

Help CenterFile Exchange 中查找有关 Operators and Elementary Operations 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by