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

5 ビュー (過去 30 日間)
Mohamuud hassan
Mohamuud hassan 2015 年 5 月 16 日
編集済み: Stephen23 2015 年 5 月 16 日
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.

採用された回答

Stephen23
Stephen23 2015 年 5 月 16 日
編集済み: Stephen23 2015 年 5 月 16 日
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

その他の回答 (2 件)

Purushottama Rao
Purushottama Rao 2015 年 5 月 16 日
編集済み: Purushottama Rao 2015 年 5 月 16 日
for k=1:4
f(k)=letters{k}(1);
end
for k=1:4
g(k)=letters{k}(2);
end

singh
singh 2015 年 5 月 16 日
for k=1:length(letters)
f(k)=letters{k}(1)
g(k)=letters{k}(2)
end

カテゴリ

Help Center および File ExchangeCell Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by