How to generate c code of dsp.MedianFilter?

1 次查看(过去 30 天)
I am attempting to generate code from dsp.MedianFilter. I believe I may not be abiding by the limitations stated here: https://www.mathworks.com/help/coder/ug/use-system-objects-in-matlab-code-generation.html
However, I am sure what is wrong exactly. When I attempt to generate code, I get:
"Error determining type for input 'movMed: medObject' ".
"Class dsp.MedianFilter is not supported by coder.Type as it is a handle class."
Am I setuping this up correctly? Thanks.
testbench.m
t = 1:1:12;
medObject = dsp.MedianFilter('WindowLength',4);
for i = 1:12
fil(i) = movMed(i, medObject); %
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
movMed.m
function f = movMed(t, medObject)
f = medObject(t);
end

回答(1 个)

Ezra Stein
Ezra Stein 2021-9-23
Hi Chase,
There is currently a limitation in MATLAB Coder which prevents using handle classes as top-level entry-point arguments (inputs or outputs to entry point functions). For details, please see the link below:
In your case, dsp.MedianFilter is a handle class object so it cannot be used as an argument to the entry point function 'movMed'. The error you are observing regarding 'coder.Type' is a consequence of attempting to specify a handle class as an argument to an entry point function.
As a possible workaround, you can move the creation of the 'dsp.MedianFilter' object inside of the entry point so that it is no longer needed as an argument:
function f = movMed(t)
medObject = dsp.MedianFilter('WindowLength', 4);
f = medObject(t);
end
>> codegen movMed -args 0
MATLAB Coder is still capable of generating code for handle class objects as long as those objects do not escape the generated code via the inputs or outputs of the entry points.

类别

Help CenterFile Exchange 中查找有关 Input Specification 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by