How to get xml-Data in Simulink

6 ビュー (過去 30 日間)
Andreas
Andreas 2013 年 7 月 15 日
Hello, i want to make a simulink model, where a xml-file can be read every single time step. Therefore I used the xmlread-function in a Matlabfunction-block as u can see below.
coder.extrinsic('xmlread')
xDoc=[];
xDoc=xmlread('OUTPUT_PIN_DATA_Matlab.xml');
a=str2double(xDoc.getElementsByTagName('o').item(0).getAttribute('p0'));
The used xml-file looks like this:
<?xml version="1.0"?>
<e id="9">
<i p0="4.332"/>
<o p0="21.66"/>
</e><e id="32">
<i p0="85.0"/>
<o p0="94.53"/>
</e>
I get an error message: Referencing a component from array of non-scalar values is not supported for code generation. Is it even possible to get the data of a xml-file in Simulink? Or is the Matlabfunction the problem? In Matlab I don't have that problem. I can read the data with the same code in the workspace... Thank you very much

回答 (1 件)

Kaustubha Govind
Kaustubha Govind 2013 年 7 月 15 日
I'd recommend that you use an Interpreted MATLAB Function block or a MATLAB S-function block to implement this. The MATLAB Function block that you are currently using needs to generate C code from the MATLAB code for execution. However, XMLREAD is not compatible with code generation. Instead, you should use blocks that don't attempt to generate code from the MATLAB code.
  1 件のコメント
Andreas
Andreas 2013 年 7 月 15 日
So it is possible to convert this Code into C-Code or a S-Function? What is faster in Simulink? I have to say, I dont really get the problem. Everything works just fine in Matlab. I Run the m-File and get the data in my workspace. Why doesnt that work in Simulink? Or is there an easier way to get data from a xml-file into Simulink?

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

カテゴリ

Help Center および File ExchangeSimulink Functions についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by