Getting type name mismatch error while converting below code into c code via matlab coder feature
Mostrar comentarios más antiguos
persistent chanObj;
if isempty(chanObj)
if ChannelType ==1 chanObj = comm.MIMOChannel('SampleRate',1000,'MaximumDopplerShift', 70,'PathDelays', [0 -3 -6 -8 -17.2],'AveragePathGains', [0 -3 -6 -8 -17.2],'RandomStream','mt19937ar with seed','Seed', 100,'NumTransmitAntennas',1 ,'TransmitCorrelationMatrix', eye(1),'NumReceiveAntennas', 1,'ReceiveCorrelationMatrix', eye(1),'PathGainsOutputPort', true,'NormalizePathGains', true,'NormalizeChannelOutputs', true); else chanObj = comm.LTEMIMOChannel('SampleRate', 1000, 'Profile', 'EVA 5Hz', 'AntennaConfiguration','1x2', 'CorrelationLevel','Medium','RandomStream','mt19937ar with seed','Seed',100,'PathGainsOutputPort', true); end end
"Type name mismatch (comm.MIMOChannel ~= comm.LTEMIMOChannel)"
1 comentario
Ryan Mott
el 2 de Ag. de 2019
As a strongly-typed language, C++ needs to know the type to the variable chanObj ahead of run time. It cannot wait to choose between the type MIMOChannel and the type LTIMIMOChannel until the code is running.
To do this directly in C++, both MIMOChannel and LTEMIMOChannel classes need to be subclasses of the same base class, and chanObj's type needs to be that base class. Otherwise, the compiler cannot assign
Then, to access a method of either class via the variable chanObj, both subclasses need to inherit that method from the parent class, and override the base class's version of that method if it the two subclasses need to implement that method in different ways.
MATLAB is much more flexible flexible - you can assign an object of any type to chanObj, and MATLAB will wait until it needs to execute a method to see if chanObj is a type of class which has that method. So you don't need to tell MATLAB that MIMOChannel and LTEMIMOChannel are subclasses and chanObj is the superclass.
Unfortunately, Coder does need to know to make chanObj the base variable's type, and at present there is no way to give that information to Coder. Coder will make chanObj variable either of type MIMOChannel or of type LTEMIMOChannel, and tyring to leave the option to assign either type at run time prompts Coder to object that MIMOChannel and LTEMIMOChannel are different types.
This polymorphic behavior is extremely powerful, but since MATLAB and C++ implement it in such different ways, your design intent is lost in translation. In cases like this your options may be scarce. I can think of two:
- keep all your uses of the channel object inside one big if-else statement or
- create both variables, one for each class, and anyplace you would use chanObj, use an if-else structure to select which variable you operate on.
Respuestas (0)
Categorías
Más información sobre Camera Pose Estimation and 3-D Reconstruction en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!