function coder.newtype not supported for code genertion

Hello friends,
Matlab coder asked me to make a input variable (for a function) as constant by using newtype.
After I did it, it says that the coder.newtype is not supported.
Anyone?
Thanks

Respuestas (1)

Can you elaborate on where you used coder.newtype? If using the codegen command you can:
codegen myFunction -args {coder.typeof(1,[10,20],[0,1])}
To pass a constant input use:
codegen myFunction -args {coder.Constant(magic(3))}
Lastly, can you copy and paste the exact error message you're getting? It seems like something we could improve.

6 comentarios

Tamar Harpaz
Tamar Harpaz el 18 de Abr. de 2019
Editada: Tamar Harpaz el 18 de Abr. de 2019
First, thanks.
This is the error :Function 'typeof' not supported for code generation.
This is a peace of the code: ( the last line is the error line)
Thanks
function [stim]=createHRTF(angle)
%load 'ReferenceHRTF.mat' hrtfData sourcePosition
hrtfDB= load ('ReferenceHRTF.mat');
hrtfData=hrtfDB.hrtfData;
sourcePosition=hrtfDB.sourcePosition;
hrtfData = permute(double(hrtfData),[2,3,1]);
sourcePosition = sourcePosition(:,[1,2]);
% 344-360 left 0-90Right
desiredAz =0;
desiredEl = 0;
if angle<0
angle=360+angle;
end
angle=double(angle);
desiredAz = desiredAz+angle;
desiredPosition = [angle 0];
leftChannelVec=[];
rightChannelVec=[];
fileReader = dsp.AudioFileReader('C:\Users\User\Downloads\createHRTF\stim.wav');
deviceWriter = audioDeviceWriter('SampleRate',fileReader.SampleRate);
interpolatedIR = interpolateHRTF(hrtfData,sourcePosition,desiredPosition);
leftIR = squeeze(interpolatedIR(:,1,:))';
rightIR = squeeze(interpolatedIR(:,2,:))';
y = dsp.FIRFilter('Numerator',coder.Constant('constant', leftIR));
Got it. The issue is the call to coder.Constant. That is meant to be used as an input to codegen not in your MATLAB code. For example:
codegen myFunction -args {coder.Constant(1), otherArg}
If you'd like to forcibly constant fold something inside your MATLAB code, you should instead use coder.const
function y = foo()
y = coder.const(svd(magic(30)));
end
Tamar Harpaz
Tamar Harpaz el 18 de Abr. de 2019
Editada: Tamar Harpaz el 18 de Abr. de 2019
Thanks
but still error with "The input to coder.const cannot be reduced to a constant." for the same line
For coder.const to succeed, the input to it must be able to have a constant value computed for it. Look back through your code to find the variables that lead to the value of leftIR. Test each one of those with coder.const to find the root value which is non-constant.
Glancing over the code it looks like one of the dependencies leads to load. The output of load is never constant. You can instead try coder.load which always produces a constant value rather than load which is a runtime value.
Thanks again.
I implemented your advice.
but a little problem for that 2 first lines:
hrtfDB= load ('ReferenceHRTF.mat');
hrtfData=coder.const(hrtfDB.hrtfData);
The output of a call to 'load' is not assigned to a variable. Assign its output to a variable without subscripting when adding hrtfDB to the coder.const too.
Thanks
Rather than:
hrtfDB= load ('ReferenceHRTF.mat');
hrtfData=coder.const(hrtfDB.hrtfData);
Try using:
hrtfDB = coder.load ('ReferenceHRTF.mat');
hrtfData = hrtfDB.hrtfData;

Iniciar sesión para comentar.

Productos

Versión

R2019a

Etiquetas

Preguntada:

el 17 de Abr. de 2019

Comentada:

el 19 de Abr. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by