MATLAB Answers

Uppercase string from the cell array

11 views (last 30 days)
I have a cell array a = {'AA_DFA_DD' ,'DSFA_dfaf' ,'DDDD' , 'DFE1' ,'dfs_DD'}
How can extract only the upper case string from the cell array
my answer should be {'AA_DFA_DD',[],'DDDD','DFE1',[]}
How can i do this?
Thanks a lot
  1 Comment
Stephen
Stephen on 12 Aug 2015
+1 for a clear question with input and output examples.

Sign in to comment.

Accepted Answer

Stephen
Stephen on 12 Aug 2015
Edited: Stephen on 12 Aug 2015
regexp(a,'^[^a-z]+$','match')
  2 Comments
Stephen
Stephen on 12 Aug 2015
^ % match start of string
[^a-z] % match any character EXCLUDING lower-case
+ % repeated one or more times
$ % match end of string
These are all explained in the documentation:

Sign in to comment.

More Answers (1)

Azzi Abdelmalek
Azzi Abdelmalek on 12 Aug 2015
Edited: Azzi Abdelmalek on 12 Aug 2015
out=a(cellfun(@(x,y) isequal(x,y),a,upper(a)))
or
out=cell(size(a))
idx=cellfun(@(x,y) isequal(x,y),a,upper(a))
out(idx)=a(idx)

Community Treasure Hunt

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

Start Hunting!