sscanf syntax/usage question
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi
I have been using sscanf to extract information from some ascii filenames as follows:
files = dir('*.ascii);
values = sscanf(files(X).name, '%*c%d%*3c');
My filenames are in the format x10mm y20mm.ascii where the numbers vary depending on the x and y position of the data inside the file, and (for this example) the above code gives me the output:
values = [10;20]
This is the outcome that I want, but the problem is that I don't understand why it works. I managed to work out the format syntax by trial and error, reasoning that %*1c ignores the first character (x), %d reads the integers (1 and 0), %*3c ignores the next three characters (m,m,y) and so on; but I expected to require another %d and then a %*8c to read the second set of integers and ignore the remainder.
Can anyone explain why the code above gives the correct outcome?
Thanks for any help Steve
댓글 수: 2
Thomas
2012년 7월 2일
sscanf reads data from a str. Where have you loaded the data in the string?
You question is a little ambiguous as to where you are getting stuck, is it at the file read stage or have you read your file and cannot get the values in the array.. (the dir command only lists the files .ascii and puts the name in the varaiable files it does not read the contents of the file..
채택된 답변
Walter Roberson
2012년 7월 2일
sscanf() re-uses the format if you have not reached the end of the string, but stops if there is a format mismatch.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Simulink Environment Customization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!