Editing Data in a Cell Array

3 ビュー (過去 30 日間)
Jake Farley
Jake Farley 2017 年 1 月 26 日
コメント済み: Walter Roberson 2017 年 1 月 26 日
I have a list of names in a text document given in the format: 1 last,first 2 last,first 3 last,first ...etc What i've done so far is
data = fopen('names.txt');
array = textscan(data, '%s','Delimiter','#');
from here, I have created a 1x1 cell that contains a 10x1 cell with the names split up:
1 last,first
2 last,first
3 last,first
What I would like to do is remove the numbers from this list, but since it is a cell array and not a normal array, I'm not sure how to go about this. I've tried using cell2mat and strrep but didn't have any luck. Any help would be appreciated.
thanks!

採用された回答

Walter Roberson
Walter Roberson 2017 年 1 月 26 日
It would seem to make more sense to change your format to '%d%s%*[,]%s' or something similar -- that is, to break it up as you read it.
In any case, with a cell array of strings, you can
regexprep(array{1}, '^\d+\s+/', '', 'lineanchors')
  2 件のコメント
Jake Farley
Jake Farley 2017 年 1 月 26 日
Thank you! Now would there be a way to put them in "first last" order instead of "last, first"? Or should that be done prior.
Walter Roberson
Walter Roberson 2017 年 1 月 26 日
regexprep(array{1}, '^\d+\s+([^,]+),\s*(.*)', '[$2, $1]', 'lineanchors')

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

その他の回答 (0 件)

カテゴリ

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