converting cells with strings inside cells into strings inside cells

조회 수: 1 (최근 30일)
Micha
Micha 2018년 7월 24일
편집: Micha 2018년 7월 24일
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
  댓글 수: 2
Paolo
Paolo 2018년 7월 24일
Can you show a sample of array_of_strings?
Micha
Micha 2018년 7월 24일
array_of_strings = {'a @one@', 'a @two@', 'a@three@'};

댓글을 달려면 로그인하십시오.

채택된 답변

Paolo
Paolo 2018년 7월 24일
편집: Paolo 2018년 7월 24일
cellfun(@(x) regexp(x,'(?<=@)(.*)(?=@)','match'),array_of_strings)
Or
cellfun(@(x) regexp(x,'(?<=@)(.*)(?=@)','tokens','once'),array_of_strings)
  댓글 수: 6
Paolo
Paolo 2018년 7월 24일
>>horzcat(new_array{:})
{'one'} {'two'} {'three'}
Does this help?
Micha
Micha 2018년 7월 24일
편집: Micha 2018년 7월 24일
That seems to do the trick
Thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by