Concatenate string to string array in efficient way

7 ビュー (過去 30 日間)
Mate D
Mate D 2020 年 5 月 20 日
コメント済み: Mate D 2020 年 5 月 20 日
Hey,
Is there any efficient way to concatenate string to string array in such way that i get from this strings:
strStart = '_';
strMsgArray = {"Ab", "Ac", "Ad"};
strEnd = 'x_';
this result:
strMsgArray = {"_Abx_", "_Acx_","_Adx_"};
They way im doing it atm is with a for-loop, but its not very efficient if size(strMsgArray,2) is large
My approach:
for k=size(strMsgArray,2)
strMsgArray{k} = strjoin({strStart,strMsgArray{k},strEnd});
end
Afterwards I'm using it to check if any of this Expressions are in other string:
x = cellfun(@(X)~isempty(regexpi(cellFileslist{dat},X)),strMsgArray);

採用された回答

Jeff Miller
Jeff Miller 2020 年 5 月 20 日
strMsgArray = strcat(strStart,strMsgArray,strEnd)
  1 件のコメント
Mate D
Mate D 2020 年 5 月 20 日
Thanks :) Way more efficient! Thought strjoin and strcat act the same, thats why I did not used it.

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

その他の回答 (0 件)

カテゴリ

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