chidri asked . 2021-09-17

Why does my referenced model with the Embedded MATLAB block not work with frame-based signals?

I built a model which contains frame-based signals and an Embedded MATLAB block, which just runs fine. When I put some parts of my model in a subsystem it also works fine. However when I use model referencing instead of a subsystem, my model produces an error when trying to run:
 
 Cannot propagate frame-based signal from output port 1 of 'mymodel/Constant' to input port 1 of 'mymodel/Model' because this input port expects a sample-based signal. Consider inserting an Unbuffer in the signal path.

The model is exactly the same, but now only some part has been moved to an external referenced file.

model , referencing. , embedded , matlab , frame , based , signals

Expert Answer

Neeta Dsouza answered . 2024-05-20 12:49:40

This is expected behavior. At compile time Real-Time Workshop needs to know the signal properties in order to be able to compile the code properly.
 
It is not possible to have dynamically sized inputs or outputs for referenced models. When a referenced model is compiled without any knowledge of the model in which it will be used later on, the size and sampling mode for all signals needs to be set explicitly as it cannot be inherited from the referencing model. In the case that the signal size is not set explicitly, it will use a default of a sample based 1x1 signal. So the model will compile succesfully, however its sizes and sampling mode will not match that of the referencing model and therefore lead to an error at runtime.
There are three ways of resolving this problem:
 
1) Make sure that you set the sizes and sampling modes of all inports and outports correctly in the referenced model so that they are known at compile time. The drawback of this method is that you cannot use a single referenced model for handling signals of different sizes and a change in signal size of the top-level model requires a change in the referenced model. It will, however, allow you to have the normal benefits of a referenced subsystem like speed of execution and incremental code generation.
 
In order to set the correct sizes for inports, please follow the following steps:
 
a. In the referenced model, open the inport that is taking a value from the referencing model

b. Go to the 'Signal Attributes' tab

c. Under 'Port dimensions' make sure you set the correct size of the incoming signal (do not leave it at -1 for inherited)

d. Under 'Sampling mode' make sure you select 'Frame based'
2) Make sure to set the sampling mode of all affected inports to be 'Frame based' as described above and let the signal that comes out resolve to a Simulink.Signal object in the workspace that has the correct Dimensions and SamplingMode properties set. In this way, Real-Time Workshop will resolve all signals to Simulink.Signal objects in the workspace and regenerate the code when necessary. The benefits and drawbacks are similar for the above mentioned approach, however, with the additional benefit of easier maintainability of your code by bookkeeping in an initialization .m file.
 
3) Do not use model referencing at all, but a use subsystem instead. This approach will result in less speed during simulation and not allow for incremental code generation, however it will allow Real-Time Workshop to determine the size of all signals at compile time. So a single subsystem can be reused many times from a library without changing its contents. Besides, this will allow your final system to contain differently sized frame-based signals and still use a single subsystem.
 
In the attached .zip-file there are several examples of how the above techniques can be applied:
  • model_to_implement.mdl - Shows the full model that is to be implemented
  • model_with_subsys.mdl - Shows how this can be done with a simple subsystem
  • model_with_ref_default.mdl and ref_model_default.mdl - Show how just copying the contents of the subsystem to a new model leads to the error that you are getting
  • model_with_ref_inports_set.mdl and ref_model_inports_set.mdl - Show how the first mentioned method is applied
  • model_with_ref_simulinksignal.mdl and ref_model_simulinksignal.mdl - Show how the second mentioned method is applied
 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.