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 で Cell Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!