From: Sarat Chandra Vegunta on
Hi,

I am trying to use embedded function block to incorporate m-file code that will manipulate data at every simulink simulation time step.

When I try to run the simulation I get the following error message:
Subscripting into an mxArray is not supported. Function 'Embedded MATLAB Function' (#18.1137.1148), line 24, column 11: "cpfmag(idx)".

Code I have problems with is below. Matlab reports issues at lline 4.

1. function val = get_percentile(cpfmag, cumprob, limit)
2. idx = 0;
3. [dummy, idx] = min(abs(cumprob - limit));
4. val = cpfmag(idx);
5. end

Here the function get_percentile accepts input arrays 'cpfmag' and 'cumprob' (both cpfmag and cumprob are 1x10000 matrices) and a limit (1x1) variable as inputs, and calculated the idex where subsequent value have to retreived from 'cpfmag' array. The code gets stuck at line 4 where variable val (a 1x1) tries to assign a value of 'cpfmag' at index 'idx'.

I think the problem is due the difference in variable 'val' (1x1) and 'cpfmag' (1x10000) sizes. However I would have thought cpfmag(idx) would give a size 1x1 and fits the 'val' 1x1 size.

Wondering if someone could help me with this problem and suggest me a solution.

Thanks a lot in advance!

Regards,
Chandra
From: Michael Hosea on
Apparently, where cpfmag is first defined, before it is passed into this
function, it is an mxArray, not a regular C data type. It means you must
have gotten this array from an extrinsic function. Check out the
documentation for eml.extrinsic. There should be something about dealing
with extrinsic functions. In a nutshell, you must pre-define the output
size and type in order for the Embedded MATLAB compiler to generate
automatically the code to convert mxArray data to an intrinsic C type.
--
Mike

"Sarat Chandra Vegunta" <scvegunta(a)gmail.com> wrote in message
news:hj4nvl$oo0$1(a)fred.mathworks.com...
> Hi,
>
> I am trying to use embedded function block to incorporate m-file code that
> will manipulate data at every simulink simulation time step.
>
> When I try to run the simulation I get the following error message:
> Subscripting into an mxArray is not supported. Function 'Embedded MATLAB
> Function' (#18.1137.1148), line 24, column 11: "cpfmag(idx)".
>
> Code I have problems with is below. Matlab reports issues at lline 4.
>
> 1. function val = get_percentile(cpfmag, cumprob, limit)
> 2. idx = 0;
> 3. [dummy, idx] = min(abs(cumprob - limit));
> 4. val = cpfmag(idx);
> 5. end
>
> Here the function get_percentile accepts input arrays 'cpfmag' and
> 'cumprob' (both cpfmag and cumprob are 1x10000 matrices) and a limit (1x1)
> variable as inputs, and calculated the idex where subsequent value have to
> retreived from 'cpfmag' array. The code gets stuck at line 4 where
> variable val (a 1x1) tries to assign a value of 'cpfmag' at index 'idx'.
>
> I think the problem is due the difference in variable 'val' (1x1) and
> 'cpfmag' (1x10000) sizes. However I would have thought cpfmag(idx) would
> give a size 1x1 and fits the 'val' 1x1 size.
>
> Wondering if someone could help me with this problem and suggest me a
> solution.
>
> Thanks a lot in advance!
>
> Regards,
> Chandra


 | 
Pages: 1
Prev: phase in FFT
Next: run a simulink in mfile