# how i can get the first and second letters in cell data

7 views (last 30 days)
Mohamuud hassan on 16 May 2015
Edited: Stephen23 on 16 May 2015
hello all;
i want to get the first and second letters of each row
letters={'Aliadan';'FadumoHassan'; 'Buraaleabi';'kadradahir'};
so, how i can assign first charac of each row in one vector and the second character in each row in another vector.
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Accepted Answer

Stephen23 on 16 May 2015
Edited: Stephen23 on 16 May 2015
This can be easily achieved using cellfun and a simple anonymous function:
>> vec = {'Aliadan'; 'FadumoHassan'; 'Buraaleabi'; 'kadradahir'};
>> cellfun(@(s)s(1),vec)
ans =
A
F
B
k
>> cellfun(@(s)s(2),vec)
ans =
l
a
u
a
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### More Answers (2)

Purushottama Rao on 16 May 2015
Edited: Purushottama Rao on 16 May 2015
for k=1:4
f(k)=letters{k}(1);
end
for k=1:4
g(k)=letters{k}(2);
end
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

singh on 16 May 2015
for k=1:length(letters)
f(k)=letters{k}(1)
g(k)=letters{k}(2)
end
##### 0 CommentsShow -2 older commentsHide -2 older comments

Sign in to comment.

### Categories

Find more on Data Types in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!