how to sort table by row sub-string values?

조회 수: 7 (최근 30일)
roudan
roudan 2021년 7월 26일
댓글: Star Strider 2021년 7월 26일
Hi
I have a table like shown in the first picture. I'd like to sort this table using the last 2 characters of string, for example, 01A58, 02A58, 01A59, I'd like to sort it by 58 or 59. The 2nd pictures show the table I'd like to have . How to do it? I am looking at the command below and still not sure how to do it? Anyone can help me? Thanks

채택된 답변

Star Strider
Star Strider 2021년 7월 26일
Try this —
wellname = {'01A58' rand; '01A59' rand; '01A62' rand; '01A63' rand; '01A66' rand; '01A58' rand; '01A59' rand}
wellname = 7×2 cell array
{'01A58'} {[0.5053]} {'01A59'} {[0.4580]} {'01A62'} {[0.9698]} {'01A63'} {[0.6966]} {'01A66'} {[0.2968]} {'01A58'} {[0.2999]} {'01A59'} {[0.3551]}
wellnamesuffix = extractAfter(wellname(:,1),'A')
wellnamesuffix = 7×1 cell array
{'58'} {'59'} {'62'} {'63'} {'66'} {'58'} {'59'}
[wellsort,ix] = sort(wellnamesuffix)
wellsort = 7×1 cell array
{'58'} {'58'} {'59'} {'59'} {'62'} {'63'} {'66'}
ix = 7×1
1 6 2 7 3 4 5
wellname_sorted = wellname(ix,:)
wellname_sorted = 7×2 cell array
{'01A58'} {[0.5053]} {'01A58'} {[0.2999]} {'01A59'} {[0.4580]} {'01A59'} {[0.3551]} {'01A62'} {[0.9698]} {'01A63'} {[0.6966]} {'01A66'} {[0.2968]}
.
.
  댓글 수: 2
roudan
roudan 2021년 7월 26일
Yes it worked perfectly. Thank you Star Strider. I appreciate it
Star Strider
Star Strider 2021년 7월 26일
As always, my pleasure!
.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by