How to pick specified matching part of the string

2 ビュー (過去 30 日間)
Mekala balaji
Mekala balaji 2017 年 12 月 2 日
コメント済み: Jan 2017 年 12 月 2 日
Hi,
I have cell array as shown below:
A050K190E3T15R40
B060L110E8T15R43
F050K230E2T25R40
G050K590E2T15R40
P050L590E2T15R40
I want to take the numerical part left side to the "E" and immediate right side numerical part of "E" and Including "E".
Desired Output:
190E3
110E8
230E2
590E2
590E2
  1 件のコメント
Greg
Greg 2017 年 12 月 2 日
Kudos and thank you for a fantastic post. Formatting, example input and desired output. Makes it easy to answer the question.

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

採用された回答

Greg
Greg 2017 年 12 月 2 日
Regular expressions for the win.
out = regexp(in,'\d*E\d*','match','once');
The 'once' means one time per cell element, and greatly simplifies the output if you know for sure there should only be one match in each element.
  2 件のコメント
Mekala balaji
Mekala balaji 2017 年 12 月 2 日
Thanks, Sir, It works.
Jan
Jan 2017 年 12 月 2 日
@Mekala: Then please unaccept my answer and accept this one. Thanks.

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

その他の回答 (1 件)

Jan
Jan 2017 年 12 月 2 日
The example looks like you want the substring from the indices 6 to 10:
Data = {'A050K190E3T15R40', ...
'B060L110E8T15R43', ...
'F050K230E2T25R40', ...
'G050K590E2T15R40', ...
'P050L590E2T15R40'};
Result = cellfun(@(c) c(6:10), Data, 'UniformOutput', 0)
  1 件のコメント
Mekala balaji
Mekala balaji 2017 年 12 月 2 日
No Sir,
It's not fixed to extract 6~10 indices. I just need to trace "E", and extract numerical left & right side to "E" including E.
A050K190E3T15R40
B060L110E8T15R43
F050K230E2T25R40
G050K590E2T15R40
P50L590E2T15R40
K70L59E2T15R40
As40L5E2T15R40
Desired Output:
190E3
110E8
230E2
590E2
590E2
59E2
5E2

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

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by