Reference to non-existent field 'mathworks'

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 件のコメント

Geoff Hayes
Geoff Hayes 2017 年 2 月 23 日
Jake - which version of MATLAB are you using? I'm running R2014a on OS X, and when I run the following (in the command window)
>> methods view com.mathworks.xml.XMLUtils
I observe a list of all the methods for this class. What do you see when you try the same?
Jake Conley
Jake Conley 2017 年 2 月 23 日
I am running Matlab R2015b. When I run the above in my command window, I hit an error:
>> methods view com.mathworks.xml.XMLUtils
Error using methods
Unknown command option.
Did I input the command wrong? I am not too familiar with the proper syntax for the methods function.
Geoff Hayes
Geoff Hayes 2017 年 2 月 23 日
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
Jake Conley
Jake Conley 2017 年 2 月 23 日
Thank you for the help Geoff! Jan solved the problem, turns out I was using "com" as a variable that Matlab was trying to call in the docNode line.
Cheers!

サインインしてコメントする。

 採用された回答

Jan
Jan 2017 年 2 月 23 日
編集済み: Jan 2017 年 2 月 23 日

3 投票

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 件のコメント

Jake Conley
Jake Conley 2017 年 2 月 23 日
"com" is a 1x8 structure generated by the first script. Checking "com" when the XML script hits the error shows no changes to "com". Using which com -all results in "com is a variable".
There is one structure loaded by the first script using the importdata() function, but it is not required by the XML writing script. I have tried the importdata() and load() functions with the same results. The loaded structure is a 1x1 structure with 8 fields, each with a 10x1 array of values.
When running dbstop if error, the XML writing script hits the same error of:
Reference to non-existent field 'mathworks'.
Error in ScriptName(line 3)
docNode = com.mathworks.xml.XMLUtils.createDocument('XMLName');
I also checked the file and product requirements to see if there was a missing file required to run the script, but the fList just has the script location (no other required files) and pList just has the base Matlab product:
Name: 'MATLAB'
Version: '8.6'
ProductNumber: 1
Certain: 1
I know that this is a difficult question to debug without the full script and files available to test. Thank you for your help.
Geoff Hayes
Geoff Hayes 2017 年 2 月 23 日
Jake - is the variable com in the same workspace as you are trying to call
docNode = com.mathworks.xml.XMLUtils.createDocument('XMLName');
If so, then it sounds like MATLAB is trying to use the com variable for com.mathworks... and since mathworks isn't a field in com, then the error makes sense. Try renaming com to something else.
Jake Conley
Jake Conley 2017 年 2 月 23 日
YOU GOT IT! Congratulations! I'm an idiot apparently, hahaha. That is exactly what Matlab was trying to do. I renamed "com" and the script runs without a problem.
Thank you!
Jan
Jan 2017 年 2 月 23 日
編集済み: Jan 2017 年 2 月 23 日
See [EDITED] in my answer.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeHistorical Contests についてさらに検索

製品

質問済み:

2017 年 2 月 23 日

編集済み:

Jan
2017 年 2 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by