Changeset 450 for trunk/src/xml2struct.m
- Timestamp:
- Jun 12, 2012, 12:27:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/xml2struct.m
r379 r450 15 15 16 16 17 function out=convert_string(s )18 info=whos('s ');17 function out=convert_string(ss) 18 info=whos('ss'); 19 19 switch info.class 20 20 case 'struct' 21 names = fieldnames(s );21 names = fieldnames(ss); 22 22 for k=1:length(names) 23 out.(names{k})=convert_string(s .(names{k}));23 out.(names{k})=convert_string(ss.(names{k})); 24 24 end 25 25 case 'char' 26 if isempty(regexp(s,'^(-*\d+\.*\d*\ *)+$'))% if the string contains a set of numbers (with possible sign and decimal) separated by blanks 27 out=s; 26 if isempty(regexp(ss,'^(-*\d+\.*\d*\ *)+$'))% if the string does not contains a set of numbers (with possible sign and decimal) separated by blanks 27 sep_ind=regexp(ss,'\s&\s');% check for separator ' & ' which indicates column separation in tables 28 if ~isempty(sep_ind) 29 sep_ind=[-2 sep_ind length(ss)+1]; 30 for icolumn=1:length(sep_ind)-1 31 out{1,icolumn}=ss(sep_ind(icolumn)+3:sep_ind(icolumn+1)-1); 32 end 33 else 34 out=ss; %reproduce the input string 35 end 28 36 else 29 out=str2num(s );37 out=str2num(ss); 30 38 end 31 39 case 'cell' 32 for ilist=1:numel(s )33 out(ilist,:)=str2num(s {ilist});40 for ilist=1:numel(ss) 41 out(ilist,:)=str2num(ss{ilist}); 34 42 end 35 43 otherwise 36 out=s ;44 out=ss; 37 45 end 38 46
Note: See TracChangeset
for help on using the changeset viewer.