フィルターのクリア

How can I join chars to a string vector?

3 ビュー (過去 30 日間)
Thodoris Manousis
Thodoris Manousis 2017 年 5 月 7 日
編集済み: dpb 2017 年 5 月 7 日
Hi everyone, I have a char vector 85x19 and I would like to combine all the characters line by line into a string vector 85x1. The char vector is like this:
2015-06-25_12:00:00
2015-06-25_13:00:00
2015-06-25_14:00:00
2015-06-25_15:00:00
2015-06-25_16:00:00
2015-06-25_17:00:00
....... and goes on
Any help would be apreciated! Thank you

回答 (2 件)

dpb
dpb 2017 年 5 月 7 日
編集済み: dpb 2017 年 5 月 7 日
Surprisingly, as so often since documentation in Matlab is example- instead of syntax- driven, the actual rule one looks for isn't described... :( (I've complained of this for 20+ yr...it's improved with more examples and some amplifications, but still has ways to go...)
Anyway, rant aside
S=string(C);
is the example not given of an array; I'd surely expect it to work.
S=string(cellstr(C)); % is in the example if above doesn't
Don't have recent release with strings class here so can't test...

Philip Borghesani
Philip Borghesani 2017 年 5 月 7 日
If you really have a char array (85x19 is not a vector... these are not all that common now) and are using a recent version of MATLAB (I tested R2017a) then just call string on your array. If your array is a cellstr you should still be able to create a string array from it with the string constructor. If you actually want a 85x1 cellstr then create that with the cellstr function.
c=repmat('this is text',10,1);
c=[c,num2str((1:10)')] %char matrix
cellArrayofChars=cellstr(c)
stringVector=string(c)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by