How to set output of MATLAB function block as fixed size?

I have a MATLAB function block in Simulink. The dimensions of the output are defined by block inputs, but remain constant during the simulation. How can I get Simulink to define it as a fixed-size output?

11 Comments

Same issue. Why no one from Matlab Support answer this?
If the signals are coming from Matlab Function in simulink, there must be a way to visualize them.
For e.g. into Video Viewer or image to workspace blocks. They both dont accept the variable size data inputs.
There are two ways.
  1. Set the dimensions in the properties of the output signal.
  2. Use Simulink Signal Object
@stozaki, I am pretty sure this is the answer. Make it an answer instead of a comment.
@Fangiun,
I attached sample model and signal object definition file.
Thank you @stozaki for your example model and code.
Attached you will find a snippet of Model what I am trying and also the error I am getting.
I used your code to define the signal dimensions. Inside the Function block I have a simple y=double(rgb2gray(videoFReader)); going on.
Even after explicit definition of y dimensions, I am unable to get rid of this error. Would be great if you can try it with a video viewer.
Thanks Again,
Adil
@Adil
I don't know your MATLAB Function algorithm. But I think there is a problem.
I cannot reproduce the error.
I attach a sample model that is simulating without problems.
Regards,
stozkai
@stozkai,
Many thanks again.
If you simply replace "y=u" in your Matlab Function Block with "y = rgb2gray(u);", you shall see the error.
Regards,
Adil
@Adil
You can use "color space conversion" as rgb2gray. I created a example model and attached.
The rgb2gray function uses variable size inside the function and it seems difficult to use in Simulink.
Regards,
stozaki
Thank you for the help. I know there are other ways to get this example done. The target is actually to integrate the "external C code" into simulink. Generated from somewhere out of Matlab.
Thats why it is important to use any image processing example from which a C code can be generated. I already generated a C code out of rgb2gray() using Matlab Coder.
I am able to integrate it in a Matlab function too and compile successfully.
The issue is not the display becasue of the variable size output. This issue comes up irrespective of if it is done via rgb2gray Matlab built in function or via rgb2gray C function. Somehow Matlab Function Block doesn't like to convert image.
This problem may be a limitation of Video Viewer. Then I don't think you can get rid of this error.
The Color Space Conversion block can generate C code.
Thank you but as described, there will be later on custom code inside the funtion block, therefore it is necessary to use matlab function block for Code Generation.

Sign in to comment.

Answers (1)

* I attached model and Signal Object file.
There are two ways.
  1. Set the dimensions in the properties of the output signal.
  2. Use Simulink Signal Object
Regards,
stozaki

Products

Release

R2017b

Asked:

on 1 Aug 2018

Community Treasure Hunt

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

Start Hunting!