Split digits into 2 matrices
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to solve a card problem.
I get two hands as an imput (Let's say 5H 5C 6S 7S 10D and 2C 3S 6S 7S 10D)
For this I want to split suit and number and put them in 2 different matrices. (I ofcourse number the suits first).
I have found ways to split the digits of a number, but not to put them in 2 different matrices.
댓글 수: 0
답변 (1개)
Walter Roberson
2021년 6월 2일
편집: Walter Roberson
2021년 6월 2일
Different approaches:
cards = {'5H' '5C' '6S' '7S' '10D' 'QC' '3S' 'KS' '7S' '10D'}
ranks1 = cellfun(@(c) c(1:end-1), cards, 'uniform', 0)
suits1 = cellfun(@(c) c(end), cards, 'uniform', 0)
ranks2 = regexprep(cards, '.$', '', 'once')
suits2 = regexp(cards, '.$', 'match', 'once')
ranks3 = extractBefore(cards, lettersPattern(1) + lineBoundary)
suits3 = extract(cards, lettersPattern(1) + lineBoundary)
ranks4 = extract(cards, asManyOfPattern(characterListPattern("A1234567890JQK"),1))
suits4 = extract(cards, characterListPattern("CDHS"))
ranks5 = regexp(cards, '[0-9AJQK]+', 'match', 'once')
suits5 = regexp(cards, '[CDHS]', 'match', 'once')
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!