Using sscanf to extract numbers from string

조회 수: 8 (최근 30일)
Katelyn
Katelyn 2016년 6월 16일
댓글: Gabriel Barros 2020년 1월 8일
Hi everyone, I'm having some trouble with sscanf, I'm trying to read two sets of number from a string which looks something like this 30cycles_sample2_11_29.csv. I want to extract the last two numbers, separated by underscores. Since the format of the string won't change I'd like to just read all numbers from the string, and can separate out the ones I'd like after. I've tried sscanf('30cycles_sample2_11_29.csv','%f') and variations but can only ever read the first number, 30 in this case. Any help is appreciated!

채택된 답변

Star Strider
Star Strider 2016년 6월 16일
This works for me:
str = '30cycles_sample2_11_29.csv';
out = sscanf(str, '30cycles_sample2_%2d_%2d.csv')
out =
11
29
  댓글 수: 4
Learner
Learner 2019년 11월 12일
편집: Learner 2019년 11월 12일
Can we extract float values??
Gabriel Barros
Gabriel Barros 2020년 1월 8일
%f instead of %d, i guess

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by