Reference to non-existent field 'mathworks'
11 views (last 30 days)
Show older comments
I've been writing Matlab code that generates XML script. I haven't run into any problems until I try to bring data from another script into the XML writing one. I have researched the problem and tried their fixes, like replacing load() with importdata(), removing all clc and clear commands, etc. The error in particular occurs on the line
docNode = com.mathworks.xml.XMLUtils.createDocument('XMLName');
Matlab gives an error "Reference to non-existent field 'mathworks'". I can't seem to find any solutions that I haven't tried and don't know what else to do. If I try running the script without any data being imported it works without any problems. What could be blocking Matlab from being able to read its own XMLUtils files? I can answer any questions you have about the code itself, but cannot upload the code for security reasons.
4 Comments
Geoff Hayes
on 23 Feb 2017
my bad - I should have looked more closely at what I pasted (there was some auto-correction and so the method is methodsview, one word)
>> methods view com.mathworks.xml.XMLUtils
Accepted Answer
Jan
on 23 Feb 2017
Edited: Jan
on 23 Feb 2017
Does a variable named "com" exist in your code? Perhaps it is created by a load? Check this by using the debugger: Type this in the command window
dbstop if error
and run your code again. When it stops, check "com":
which com -all
[EDITED] After your comment:
As Geoff has said already: If com is a struct, the command with the same name is shadowed and cannot be called. This is the same as:
sum = 1
sum(1:5) % error, because "sum" is a variable now
There are some solutions:
1. Use another name for the variable. This is the best.
2. Clear the variable temporarily:
comback = com;
clear('com');
docNode = com.mathworks.xml.XMLUtils.createDocument('XMLName');
com = comback; % Huh, ugly.
3. Try if builtin gets the correct function:
docNode = builtin('com.mathworks.xml.XMLUtils.createDocument', 'XMLName');
I cannot test this currently, but it does not look nice also. Prefer not to shadow builtin function names by local variables.
4 Comments
More Answers (0)
See Also
Categories
Find more on Historical Contests in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!