我的行看起来像这样:
tmp='bla bio = 773 node = 6 bib=21 data=118 pewp= 120'
我需要获取第一个和最后一个数字 - 773,120 我试过了
sscanf(tmp,' %*s %*s %*s %f %*s %*s %*s %*s %*s %*s %f')
但是没有任何运气.. 数字 6 21 118 是随机的,其余的都是常量
最佳答案
以下方法可能会有所帮助:
% 删除所有 '='
tmp(strfind(tmp,'=')) = [];
% 设置键和索引
key = 'bio'
;
index = strfind(tmp,key);
%提取值
value = sscanf(str(index(1)+length(key):end), '%g',1);
% 要获取 pewp 的值,请设置 key = 'pewp' 并重复上述步骤
关于matlab - 解析一行以获取数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26654104/