sscanf syntax/usage question
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Thomas
il 2 Lug 2012
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..
Risposta accettata
Walter Roberson
il 2 Lug 2012
sscanf() re-uses the format if you have not reached the end of the string, but stops if there is a format mismatch.
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Simulink Environment Customization in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!