Splitting a sentence into an array of letters
조회 수: 1 (최근 30일)
이전 댓글 표시
I'm new to MATLAB. I would like to learn how to convert or split a string (maybe a sentence or a passange) to an array of letters. For example:
I have a string of 'I am happy'
I want my end result of my array to be [ 'I' ' ' 'a' 'm' ' ' 'h' 'a' 'p' 'p' 'y' '.']
How can I do that? Thank you for all your advice and help.
댓글 수: 2
Stephen23
2022년 9월 23일
Because square brackets are a concatenation operator, your two examples are equivalent (apart from the dot at the end, which appears out of nowhere):
A = 'I am happy' % I have a string of
B = [ 'I' ' ' 'a' 'm' ' ' 'h' 'a' 'p' 'p' 'y' '.'] % I want my end result of my array to be
채택된 답변
Chunru
2022년 9월 23일
str = 'I am happy' % characar array
% the char array str is stored as [ 'I' ' ' 'a' 'm' ' ' 'h' 'a' 'p' 'p' 'y'
% '.'] internaly. It only display as 'I am happy' for compactness.
%
% You can get the individual character
str(3)
% if you transpose str, it is a column vector of characters
str'
댓글 수: 3
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!