Reputation: 1101
I have lines that look like this:
tmp='bla bio = 773 node = 6 bib=21 data=118 pewp= 120'
I need to get the first and last numbers - 773,120 I tried
sscanf(tmp,' %*s %*s %*s %f %*s %*s %*s %*s %*s %*s %f')
But without any luck.. The numbers 6 21 118 are random the rest are consts
Upvotes: 2
Views: 61
Reputation: 1101
i found an easy way
temp=sscanf(tmp,'bla bio = %f node = %f bib=%f data=%f pewp= %f')
tmp(1)=temp(1)
tmp(2)=temp(5)
Upvotes: 1
Reputation: 265
The following approach might help:
% Remove all '='
tmp(strfind(tmp,'=')) = [];
% Set the key & indices
key = 'bio'
;
index = strfind(tmp,key);
%Extract value
value = sscanf(str(index(1)+length(key):end), '%g',1);
% To get value of pewp, set key = 'pewp' and repeat above steps
Upvotes: 1