Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

New to MATLAB?

Subscripting into an mxArray

Asked by ECE09 ITBHU

ECE09 ITBHU (view profile)

on 8 Aug 2011
Latest activity Commented on by Sharan Duggirala on 17 Apr 2015 at 17:31

given below is a part of the code i am writing for kalman filter but got error while converting from .m to .c/.c++

>> white_gauss=wgn(1,37000,20); q1=cov(white_gauss); q2=cov(white_gauss); q3=cov(white_gauss);

Q=[q1(L) q2(L) q3(L)] >>>
 and got following error while converting from .m to .c using matlab coder.

"Subscripting into an mxArray is not supported. "

>>how to avoid it?



ECE09 ITBHU (view profile)


1 Answer

Answer by Mike Hosea

Mike Hosea (view profile)

on 9 Aug 2011
Accepted answer

That is the error you get when you use coder.extrinsic and fail to declare the output before calling the extrinsic function. If you only want to pass the output to extrinsic functions, you don't have to, but if you want to index into the result, you have to pre-define its size and type. For example, suppose foo(x) returns a result with the same size and type as x. Then you could write

y = x;
y = foo(x);

Or if foo always returns a 4-by-1 array of int32's, you would write

y = zeros(4,1,'int32');
y = foo(x);

This tells the compiler how to deconstruct the data structure that comes back from MATLAB when the function foo is called with x as input. -- Mike



Rod (view profile)

on 16 Aug 2013

Hi, I'm having a similar problem calling the poyxpoly as extrinsic in a matlab function block in simulink.

My problem is that the output of this function is an x by 2 array, with x varying. I am therefore unable to index (an use) the output.

Would you know a way around this?

Jan Simon

Jan Simon (view profile)

on 17 Aug 2013

@Rod: Please post a new question in a new thread, and not as comment to an answer of a similar question.

Sharan Duggirala on 17 Apr 2015 at 17:31


During code generation, I keep getting the error -

' CODER.VARSIZE is not applicable to 'mxArray '. '

Has anyone encountered this/ know a way around this?

Here is a screenshot of the code generation error report :

Mike Hosea

Mike Hosea (view profile)

Contact us