Matlab有一个strtok类似C的函数,它的格式是:
token = strtok(str)
token = strtok(str, delimiter)
[token, remain] = strtok('str', ...)
还有一个字符串替换功能strrep:
modifiedStr = strrep(origStr, oldSubstr, newSubstr)
我要做的是修改原始字符串strrep以添加分隔符,然后使用strtok. 由于您已经将字符串扫描到c:
c = (c,'(','( '); %Add a space after each open paren
c = (c,')',' ) '); % Add a space before and after each close paren
token = zeros(10); preallocate for speed
i = 2;
[token(1), remain] = strtok(c, ' ');
while(remain)
[token(i), remain] = strtok(c, ' ');
i =i + 1;
end
为您提供您请求的每个字符串的线性标记数组。
strtok参考: http: //www.mathworks.com/help/techdoc/ref/strtok.html
strrep参考: http: //www.mathworks.com/help/techdoc/ref/strrep.html