how do I extract part of a cell of string values?

조회 수: 31 (최근 30일)
Susan Santiago
Susan Santiago 2018년 9월 18일
댓글: Christopher Wallace 2018년 9월 18일
I have a 1x144 cell of string values all with 12 numbers like '201808250100'. I want to extract a cell of just the last four numbers of each value. Any help with this would be appreciated

답변 (2개)

Christopher Wallace
Christopher Wallace 2018년 9월 18일
You could use a cell function.
cellfun(@(x) x(end-3:end), your_var, 'UniformOutput', false)
  댓글 수: 2
Paolo
Paolo 2018년 9월 18일
Mind that Susan mentioned she is working with a cell array of strings, and not character vectors.
Christopher Wallace
Christopher Wallace 2018년 9월 18일
Yes, Susan said that she had a cell of strings, not a character array which cellstr is meant to convert.

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


Paolo
Paolo 2018년 9월 18일
You could loop over it:
arr = {"201808250100","201808250104"}
f=cellstr(arr);
cellfun(@(x) x(end-3:end),f,'un',0)
ans =
1×2 cell array
{'0100'} {'0104'}

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by