MATLAB Answers

Attempt to extract field 'accel' from 'mxArray'

6 views (last 30 days)
Omkar Karve
Omkar Karve on 9 Oct 2018
I am trying to build a self contained function block in Simulink that will be compiled into a standalone executable that accepts a parameter input. This parameter input will be used to generate a string representing a filename (a .mat file). This .mat file will be loaded using load(filename). Here is the code: {
function result = fcn(filename)
coder.extrinsic('num2str');
coder.extrinsic('strcat');
cursimfile = strcat(num2str(filename),'.mat');
accelstruct = load(cursimfile);
accel = accelstruct.accel; %%The mat file has a field called accel which is a 2 x n array
result = someotherfunction(accel);
On the line accel=accelstruct.accel, I am getting an error 'Attempt to extract field 'accel' from 'mxArray''. My problem is that the usual solution of declaring the accel variable as a 2 x n array requires me to know the n value. I can obtain the n value by doing length(accelstruct.accel). But even this line gives me the same error. Every .mat file that I will pass to this compiled code will be of different length (n).
Any suggestions on how to get over this?

Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by