creating a list from another list

7 ビュー (過去 30 日間)
matthew arnott
matthew arnott 2013 年 3 月 8 日
I have a list where not all the elements are the same length but they mostly are lets say my list is
mylist = {'ABCD', 'DEFG', 'HIJKL'} i want to return a new list mynewlist looks like {ABC, DEF, GHI} %%- its always the first 3 letters of the old list
many thanks probably seems a bit arbtirary but struggling

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 3 月 8 日
mylist = {'ABCD', 'DEFG', 'HIJKL'}
out=cellfun(@(x) x(1:3),mylist,'un',0)

その他の回答 (1 件)

per isakson
per isakson 2013 年 3 月 8 日
>> mylist = {'ABCD', 'DEFG', 'HIJKL'}
mylist =
'ABCD' 'DEFG' 'HIJKL'
>> cellfun( @(str) str(1:3), mylist, 'uni', false )
ans =
'ABC' 'DEF' 'HIJ'
>>
  1 件のコメント
matthew arnott
matthew arnott 2013 年 3 月 11 日
i think both answers are good - i didnt realise you could only accept one - many thanks to both.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by