Subscripting into an mxArray is not supported.

part of code is:
function m = func_Dec(in)
m = zeros(in(1,1));
n_max = in(1,2);
level = in(1,3);
but errors occur at
Subscripting into an mxArray is not supported.
Function 'func_Dec.m' (#29.405.412), line 16, column 11:
"in(1,1)"

1 Comment

I got an ERROR , while running a function inside the Simulink
""Subscripting into an mxArray is not supported.""
function y = PY_MAT(r,t,v,rcs)
coder.extrinsic('tic','toc', 'system','clear'
,'clc','num2str','str2double','strsplit','cell2mat','str2num',... 'ceil','cellstr','floor','repmat','numel');
tic
% commandStr = ['C:\LegacyApp\Python27\python PY_MAT.py ',num2str(a),'
',num2str(b),' ',num2str(c),' ',num2str(d)];
commandStr = ['C:\LegacyApp\Python27\python
D:\CM_Projects\TaccTest_FreeSpaceDynamicObjects_100315_New\src_cm4sl\run_ref.py
'... ,num2str(r'),' ',num2str(t'),' ',num2str(v'),' ',num2str(rcs')];
[status, commandOut] = system(commandStr)
y = 0;
% y = zeros(size(commandOut), class(r));
y = commandOut;
K=strsplit(y,'..');
A = cell2mat(K(1));
y = str2num(A);
toc
end

Sign in to comment.

 Accepted Answer

It appears that you are using an extrinsic function (declared with coder.extrinsic) to create in, correct? In that case you need to first assign a value to in before making the extrinsic call to tell the code generation software what type to expect.
For example, suppose that the function foo returns a 3-by-4 array of real doubles. Then you would use code like:
coder.extrinsic('foo');
x = zeros(3,4);
x = foo(y);
You can see my answer:
for more information.

6 Comments

Can I ask another question? the code the i tried to run with simulink is Matlab implementation of SPIHT (without Arithmatic coding stage) and i want to run it on raspberry. there is another error occurred with variables such as :
%----------- Initialize LIP, LSP, LIS ----------------
temp = [];
bandsize = 2.^(log2(in(1,1)) - level + 1);
temp1 = 1 : bandsize;
for i = 1 : bandsize
temp = [temp; temp1];
end
% LIP=[];
% LIS=zeros(19035,3);
% LIPtemp=zeros(16361,2);
% LIStemp=zeros(40898,3);
LIP(:, 1) = temp(:);
temp = temp';
LIP(:, 2) = temp(:);
LIS(:, 1) = LIP(:, 1);
LIS(:, 2) = LIP(:, 2);
LIS(:, 3) = zeros(length(LIP(:, 1)), 1);
.... etc.
and this is error appeared for all variables such as: Undefined function or variable 'LIS'. The first assignment to a local variable determines its class.
Function 'func_SPIHT_Dec.m' (#38.750.753), line 35, column 1:
"LIS"
please help; thanks.
It would be helpful if the code were indented so that it formats as code as in your original question.
It appears as though LIS is not initialized before the assignment:
LIS(:,1) = LIP(:,1);
is that correct? Growing a matrix by indexing in this manner is generally not supported for code generation:
This is done so that more efficient C code may be generated.
You can pre-declare LIS using ZEROS or similar before assigning the columns.
Alternatively, you may consider using a CAT statement:
LIS = [LIP(:,1:2), zeros(length(LIP(:,1)),1), ...];
to directly construct LIS if that is a reasonable approach.
attached the code, if that is more helpful. I tried to pre-declare LIS using ZEROS but another error occurred showing size mismatch between the 2 matrices. If that possible to have a look at the code and give me a feedback of the possibility to run it with code generation on raspberry hardware platform. thanks a lot for your help.
Was the mismatch between LIS and one of the RHS variables? I would recommend trying to just concatenate columns onto LIS like so:
LIS = LIP(:,1:2);
LIS = [LIS, zeros(length(LIP(:,1)), 1)];
... etc.
I want to thank you for your help, and i wonder if that possible to help me more about some errors that i tried to correct some of them but others i can't correct. attached image of related errors.
<<
>>

Sign in to comment.

More Answers (1)

What are you trying to do? Zeros creates an array of zeros and you need to pass in the size of the array you want to create. Is in(1,1) that size? If so, it MUST be integer value and in that case, it will create a square array of zeros and pass it back. The other two lines don't do anything useful either.
How are you creating the array "in" in your main (calling) routine, and how are you calling func_Dec()?

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Tags

Asked:

on 22 Jun 2014

Commented:

on 13 Mar 2015

Community Treasure Hunt

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

Start Hunting!