converting cells with strings inside cells into strings inside cells

1 visualizzazione (ultimi 30 giorni)
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

Risposta accettata

Paolo
Paolo il 24 Lug 2018
Modificato: Paolo il 24 Lug 2018
cellfun(@(x) regexp(x,'(?<=@)(.*)(?=@)','match'),array_of_strings)
Or
cellfun(@(x) regexp(x,'(?<=@)(.*)(?=@)','tokens','once'),array_of_strings)
  6 Commenti
Paolo
Paolo il 24 Lug 2018
>>horzcat(new_array{:})
{'one'} {'two'} {'three'}
Does this help?
Micha
Micha il 24 Lug 2018
Modificato: Micha il 24 Lug 2018
That seems to do the trick
Thanks!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by