Is it possible for MATLAB to make string matrix?
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
John D'Errico
il 13 Dic 2016
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.
Risposte (1)
Jan
il 13 Dic 2016
Modificato: Jan
il 16 Dic 2016
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 Commenti
Walter Roberson
il 13 Dic 2016
Jan
il 16 Dic 2016
@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.
Vedere anche
Categorie
Scopri di più su Cell Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!