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

3 views (last 30 days)
a = char(abdefghijk);
I want the output 'abcdefg'

Accepted Answer

Walter Roberson
Walter Roberson on 7 Dec 2022

More Answers (2)

Vikram Ojha
Vikram Ojha on 7 Dec 2022
Edited: Vikram Ojha on 7 Dec 2022
>> a='abcdefghijk'
>> a(1:5)
ans =
In genral a(1:n) % n for index
You can consider going through following doc:, it will be helpful
In case you want you can take Matlab fundamental certification:

Steven Lord
Steven Lord on 7 Dec 2022
The extractBefore function will work both for char arrays and strings.


Find more on Resizing and Reshaping Matrices in Help Center and File Exchange



Community Treasure Hunt

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

Start Hunting!