MATLAB Answers

converting cells with strings inside cells into strings inside cells

1 view (last 30 days)
Micha
Micha on 24 Jul 2018
Edited: Micha on 24 Jul 2018
I use the following code: cellfun(@(x) regexp(x, '@(.*)@', 'tokens'), array_of_strings) The idea is to replace all the strings in the array with only the substring between the @'s. It works, the only problem is that the 'tokens' option leaves me with cells inside cells, which is inconvenient. My questions are: 1. Is there an alternative way to do it without getting cells inside cells? 2. It is interesting for me to know if there is a function that converts "cell arrays with strings inside a cell array" into simply "strings in a cell array". Thanks

Accepted Answer

Paolo
Paolo on 24 Jul 2018
Edited: Paolo on 24 Jul 2018
cellfun(@(x) regexp(x,'(?<=@)(.*)(?=@)','match'),array_of_strings)
Or
cellfun(@(x) regexp(x,'(?<=@)(.*)(?=@)','tokens','once'),array_of_strings)

  6 Comments

Show 3 older comments
Micha
Micha on 24 Jul 2018
Of course, your 2 solutions solved this problem to begin with. But I was interested if there is any function to "fix" this new condition.
Paolo
Paolo on 24 Jul 2018
>>horzcat(new_array{:})
{'one'} {'two'} {'three'}
Does this help?

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Products


Release

R2017b