MATLAB Answers

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

Asked by Susan Santiago

### Susan Santiago (view profile)

on 18 Sep 2018
Latest activity Commented on by Christopher Wallace

### Christopher Wallace (view profile)

on 18 Sep 2018
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

#### 0 Comments

Sign in to comment.

## 2 Answers

### Christopher Wallace (view profile)

Answer by Christopher Wallace

### Christopher Wallace (view profile)

on 18 Sep 2018

You could use a cell function.
cellfun(@(x) x(end-3:end), your_var, 'UniformOutput', false)

Paolo

### Paolo (view profile)

on 18 Sep 2018
Mind that Susan mentioned she is working with a cell array of strings, and not character vectors.
Christopher Wallace

### Christopher Wallace (view profile)

on 18 Sep 2018
Yes, Susan said that she had a cell of strings, not a character array which cellstr is meant to convert.

Sign in to comment.

Answer by Paolo

### Paolo (view profile)

on 18 Sep 2018

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'}

#### 0 Comments

Sign in to comment.