I have a list of strings in a char array:
'gvs(0.000000000000000e+000, 1.601985139535780e+002)'
'gvs(-5.000000000000000e-005, 1.365231866954370e+002)'
'gvs(-1.000000000000000e-004, 1.169431404340180e+002)'
'gvs(-5.000000000000000e-004, 3.187711314514890e+001)'
'gvs(-2.000000000000000e-004, 8.589930648472340e+001)'
Which I am trying to convert to an array of just the numbers (ignoring gvs, the comma and the brackets), but I can't quite work out what I'm doing wrong?
cols = length(Variables) + length(Parameters);
% currently unused
rows = length(Results);
for a = 1:rows;
Res(a,:) = sscanf ((Results{a,1}(1,:)),'%*s %f %f');
end
I've also tried textscan, but I can't get that to work right either
for a = 1:rows;
Res = cell (textscan ((Results{a,1}(1,:)),'%*s %f %f','Delimiter', {'(',' '},'MultipleDelimsAsOne',1));
end
Any help much appreciated!
Thanks
%*s
reads characters until the first whitespace. What you need is to explicitly match thegvs
string (including the parentheses). Also, there's really no point for the(1, :)
indexing, just useResults{a, 1}
instead. – Eitan T Jul 11 '13 at 11:20