Attempt to extract field 'Value' from 'mxArray'.
이전 댓글 표시
In Simulink, Im trying to get the value from a cell in an Excel Spreadsheet, but everytime I try to run the model, I get this error...
Attempt to extract field 'Value' from 'mxArray'.
Why? and how do I fix it.
PS: The error comes from disp(iiTHEVALUE.Value); (right now I'm just displaying the value in the matlab command window, once I get it working, I will start to do things with it)
This is my code in a Matlab function box in Simulink...
function count_oute = Excel(counte)
%#codegen
%%Lets Simulink know to read commands as Matlab commands
%Keep at top
coder.extrinsic('pwd');
coder.extrinsic('strcat');
coder.extrinsic('actxserver');
coder.extrinsic('invoke');
coder.extrinsic('get');
coder.extrinsic('set');
coder.extrinsic('delete');
%%Global Variables?
%%Editable Variables
Excel_File = 'If_actxserver.xlsx';
%%Defining Variables
Current_Directory = pwd;
excel_filename = strcat(Current_Directory,'\',Excel_File);
%%Keeping COM.handles active through iterations in this specific function block
%Excel handle Variables
persistent h_Excel;
if isempty(h_Excel)
%if handle is empty, define (which it is at the start of a model)
h_Excel = actxserver('Excel.Application');
end
persistent Excel_Workbook;
if isempty(Excel_Workbook)
%if handle is empty, define (which it is at the start of a model)
Excel_Workbook = invoke(get(h_Excel, 'Workbook'), 'Open',excel_filename);
end
%%If first iteration
if (counte==1)
set(h_Excel, 'Visible', 1);
disp('Started Mathcad application');
end
%%Iterate on Excel
disp('Excel Iterate #');
disp(counte);
%%Save, Close, and Quit actxservers on last iteration
if (counte==11)
iTHEVALUE = invoke(get(Excel_Workbook, 'Worksheets'),'Item','InitialVars');
iiTHEVALUE = invoke(iTHEVALUE, 'Range','A1:B4');
disp(iiTHEVALUE.Value);
invoke(Excel_Workbook,'Close');
invoke(h_Excel,'Quit');
invoke(h_Excel,'delete');
disp('Excel Closed');
end
%Out value is the same as the in value, just displaying again
count_oute=counte;
end
댓글 수: 3
Brian
2014년 3월 20일
Balaji Subramanian
2019년 3월 18일
Hi Brian,
I have the same error too.
Currently, in my case, I am sending values from an integrator to a Data Store Block.
This Data store block is output of a PV Farm -> Signal converted from DC to AC.
However in the Master Code, it displays the 'mxArray' error.
Is it because I need to store the signal as an array ? Or make it global so the Array in Master code can directly access it instead of reading the whole PV Farm file ?
Thank you
Shray
2023년 6월 18일
Can you able to find answer to this question????
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Data Import from MATLAB에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!