フィルターのクリア

How to add letters to the end of words in a string.

54 ビュー (過去 30 日間)
Thom
Thom 2011 年 11 月 28 日
回答済み: George Abrahams 2022 年 12 月 30 日
I need to add a letter to the end of an array. I have a wordbank that's arranged in an array, and I need to add a letter to the end of every word in the array. How could I do it?
I have the wordbank and I need wordbank + 's', so basically an "s" added to every word in the bank.

採用された回答

Matt Tearle
Matt Tearle 2011 年 11 月 28 日
strcat(wordbank,'s')
  1 件のコメント
Thom
Thom 2011 年 11 月 28 日
That's exactly what I needed. Thanks!

サインインしてコメントする。

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2011 年 11 月 28 日
Making guesses about what kind of array it is based upon past postings, I am going to guess one of
cellfun(@(S) [S 's'], YourArray)
or, more likely,
structfun( @(F) cellfun(@(S) [S 's'], F, wordbank2 )

George Abrahams
George Abrahams 2022 年 12 月 30 日
Old question, but for future reference, you can also do this using the plus operator and strings. The only downside is that the output will be a string array, even if the input is a cell array of character vectors.
% Input is string array. Output is string array.
wordbank = ["apple","banana","CHOCOLATE"];
wordbank + "s"
% ans = 1×3 string array
% "apples" "bananas" "CHOCOLATEs"
% Input is cell array of character vectors. Output is string array.
wordbank = {'apple','banana','CHOCOLATE'};
wordbank + "s"
% ans = 1×3 string array
% "apples" "bananas" "CHOCOLATEs"

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by