matlab sscanf format for "word1 word2 rest" parsing e.g. "n1 n2 r = 20" in matlab

You can use the following sscanf format to parse the string "n1 n2 r = 20" in MATLAB:

main.m
str = "n1 n2 r = 20";
[n1, n2, r] = sscanf(str, "%s %s %*c = %d");
67 chars
3 lines

This code will parse the string "n1 n2 r = 20" and store "n1" and "n2" as strings, and "20" as an integer in the variables n1, n2, and r respectively.

related categories

gistlibby LogSnag