MATLAB Answers

Concatenate string to string array in efficient way

6 views (last 30 days)
Mate D
Mate D on 20 May 2020
Commented: Mate D on 20 May 2020
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});
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);


Sign in to comment.

Accepted Answer

Jeff Miller
Jeff Miller on 20 May 2020
strMsgArray = strcat(strStart,strMsgArray,strEnd)

  1 Comment

Mate D
Mate D on 20 May 2020
Thanks :) Way more efficient! Thought strjoin and strcat act the same, thats why I did not used it.

Sign in to comment.

More Answers (0)