フィルターのクリア

How do I delete extra values separated by comma

2 ビュー (過去 30 日間)
Sebastian
Sebastian 2016 年 11 月 24 日
コメント済み: Sebastian 2016 年 11 月 24 日
I have some stuff in a dataset (cell) I need removed.
Essentially my dataset looks like this:
XX
XY, XX
YZ
YY
ZZ, YY, XY
However I need only the first value of each row. I've tried with some regex but I'm still fairly inexperienced with it so it doesn't yield the results I'm aiming for.
Thanks :)

採用された回答

Adam
Adam 2016 年 11 月 24 日
編集済み: Adam 2016 年 11 月 24 日
result = cellfun( @(x) x{1}, cellfun( @(x) strrep( strsplit(x), ',', '' ), myCell, 'UniformOutput', false ), 'UniformOutput', false );
works I think, but it doesn't win any prizes for neatness. You can split it over multiple lines to be a bit less daunting if you prefer.
No need for regexp though.
If your values are always just 2 letters then you can do simpler things, just accessing the first 2 elements of the cell and ignoring what comes next, but obviously that fails in the generic case.
  1 件のコメント
Sebastian
Sebastian 2016 年 11 月 24 日
Thanks. That did the trick! The values are poorly entered hospital codes that I'm trying to streamline. So they come in many shapes and sizes unfortunately.

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

その他の回答 (0 件)

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by