xml2struct - Reference to non-existent field

2 views (last 30 days)
I have a program which loads XML files into a Matlab structure, using the function
xml2struct([pathname filename])
which works really well.
This program is on a network drive "H:\" and a few folders of hierarchy. This drive is different to the one that has Matlab installed on it (C:\), and so when I run the program I 'change folder'. This all works fine.
I then save the exact same program to another drive, "E:\" with a similar (but different) amount of folder heirarchy, and no spaces in the path name.
I run the program and open the XML file (which is in the same location as previously, and on a different network drive). However, this does not run correctly; I have the error message "Reference to non-existent field 'RESULTS'" where RESULTS is a structure field that I am looking for.
I then look at the result of xml2struct, and find that the entries have been stored as 'children' which is different to how it stored them when working on the H:\ drive (they were stored as another structure hierarchy).
I have tried 'add path' and 'change folder' when running from new, but with the same error.
At no time in the code do I change directory, set path, or change path.
This is most bizzare, as it is the same program, same XML file, same code, but different network drive.
Can someone help explain why this might be occuring and how I can prevent it?

Accepted Answer

Phil Newman
Phil Newman on 9 Jun 2016
Edited: Phil Newman on 9 Jun 2016
Sorted it - I needed to point to a locally stored copy of the function by using addpath(genpath([pathname])). I tried doing this with the function stored at C:\Program Files\MATLAB\2015b\toolbox\bioinfo\biodemos but this didn't work.
I guess the function needs to be stored on the same drive as the program in order for it to work. addpath still needs to be used.

More Answers (0)

Categories

Find more on Search Path in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!