fill up a cell array with string elements
10 ビュー (過去 30 日間)
古いコメントを表示
Hye
I have to write a function that puts the words of a string in a cell array.
I've made the following script.
I already get a cell array with the right amount of cells, but they are all filled up with the first word of the string.
How do I get this right?
function [words] = giveWords(sentence)
k = split(sentence);
words = cell(1,length(k));
words(1,:) = k(1,:);
end
0 件のコメント
回答 (2 件)
Fangjun Jiang
2020 年 1 月 13 日
This is all you need
words=split('this is a sentence.')
3 件のコメント
Fangjun Jiang
2020 年 1 月 14 日
It depends on the data type of the input. In your case, you can add one more line to convert it
words=mat2cell(names,repmat(1,1,size(names,1)),repmat(1,size(names,2),1))
参考
カテゴリ
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!