|
Last change
on this file since 371 was
369,
checked in by sommeria, 14 years ago
|
|
image interpolation introduced in civ2_matlab (option decimal shift)
bug corrected in xml2struct (reading of decimal numbers fixed)
|
|
File size:
875 bytes
|
| Rev | Line | |
|---|
| [356] | 1 | % 'xml2struct': read an xml file as a Matlab structure, converts numeric character strings into numbers |
|---|
| 2 | %----------------------------------------------------------------------- |
|---|
| 3 | % function s=xml2struct(filename) |
|---|
| 4 | % |
|---|
| 5 | % OUTPUT: |
|---|
| 6 | % s= Matlab structure corresponding to the input xml file |
|---|
| 7 | % |
|---|
| 8 | % INPUT: |
|---|
| 9 | % filename: name of the xml file |
|---|
| 10 | |
|---|
| [320] | 11 | function s=xml2struct(filename) |
|---|
| 12 | t=xmltree(filename); |
|---|
| [324] | 13 | ss=convert(t); |
|---|
| [320] | 14 | s=convert_string(ss); |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | function out=convert_string(s) |
|---|
| 18 | info=whos('s'); |
|---|
| 19 | switch info.class |
|---|
| 20 | case 'struct' |
|---|
| 21 | names = fieldnames(s); |
|---|
| 22 | for k=1:length(names) |
|---|
| 23 | out.(names{k})=convert_string(s.(names{k})); |
|---|
| 24 | end |
|---|
| 25 | case 'char' |
|---|
| [369] | 26 | |
|---|
| 27 | if isempty(regexp(s,'^\d+\.*\d*$'))% if the string contains numerical characters and decimal . only |
|---|
| [320] | 28 | out=s; |
|---|
| 29 | else |
|---|
| 30 | out=str2num(s); |
|---|
| 31 | end |
|---|
| 32 | otherwise |
|---|
| 33 | out=s; |
|---|
| 34 | end |
|---|
| 35 | |
|---|
| 36 | |
|---|
Note: See
TracBrowser
for help on using the repository browser.