Is it possible for MATLAB to make string matrix?
조회 수: 5 (최근 30일)
이전 댓글 표시
Let's say I have 'file.txt' file that contains strings below.
this/is/the/first/sentence
this/is/the/second/sentence
.......
this/is/the/hundredth/sentence
what I want is that make this 100 sentences into 100 X 1 matrix with strings
And if possible, I would like to add ' ' (punctuation) for each sentence. What shall i do?
댓글 수: 2
John D'Errico
2016년 12월 13일
Why not try something? Make an effort. If you have no clue as to how to do this, then you need to start learning basic MATLAB, like how to read in a file to start.
Then you need to learn about the string processing tools one can find. Everything from regexp to the many string tools.
In MATLAB, type
help strfun
Then start reading.
When you actually have a question about MATLAB, then ask it.
답변 (1개)
Jan
2016년 12월 13일
편집: Jan
2016년 12월 16일
There is no string type in Matlab [EDITED, this claim is outdated, see Walter's comment] , but strings are vectors of type CHAR. You can create a CHAR matrix, which is padded with zeros or blanks on the right. Remember that matrices have the same length for all rows.
As you can read in the documentation (search for "string"), a list of strings is represented as "cell string" in Matlab: A cell array, which elements are strings. Cells can contain elements of different sizes. All string functions operate on cell strings also (at least I'm not aware of any exceptions), see strcmp etc.
Perhaps you want to use strrep to replace "/" by a space, but this part of the question is not clear to me.
John said it already: you find all required information about strings in Matlab's documentation. Reading it there is more efficient than asking the forum.
댓글 수: 2
Walter Roberson
2016년 12월 13일
Jan
2016년 12월 16일
@Walter: I'm getting old. I've waited too long for a string type, that I gave up hope. It would be awesome if these strings have a well defined unicode handling (I still do not know how to convert Matlab 2 byte chars to Unix 4 byte wchar type reliably) and trailing zeros for a smarter sharing with C functions. Currently the confusion is perfect, if Matlab's CHAR vectors contain zeros.
참고 항목
카테고리
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!