2

I have the following code in an embedded matlab function in simulink:

 function rad = fcn(lenkwinkel)
if lenkwinkel < 0
    rad=[0 1 0 0];
elseif lenkwinkel > 0
    rad=[1 0 0 0];
else
    rad=[0 0 0 0];
end

In the simulation I have the "lenkwinkel" variable connected to the MATLAB Function Block,which is connected to a Mux block with 4 ports.

I am trying to use the function to send a vector with 4 binary elements to the Mux block, which then should split it into 4 signals. Unfortunately, this is not working. When I try to run this, I get:

Inferred size ('[1 4]') for data 'rad' (#44) does not match back propagated size ('[4]') from Simulink.

Can anyone help me with this? Thanks a lot.

2
  • 1
    Do you mean DeMux? If the demux is connect to a Scope then the model as described works for me (in R2013b). What do you have connected to the output of the demux? Commented Apr 7, 2014 at 14:30
  • Hello there. Yes, I am sorry. I do mean DeMux. On the left side, the DeMux connects to the function and on the right side it splits into 4 port, where each connects to a product block. Thanks. Commented Apr 8, 2014 at 10:47

1 Answer 1

2

I am assuming you mean DeMux as well, please correct us if that is incorrect. From the looks of it, the MATLAB Function block has determined that the size of rad is 1-by-4 since that is the size of the value assigned to it. However, something else seems to think that the output should be of size [4] or 4-by-1. Have you manually specified the output of the MATLAB Function block to have size [4] or the size of the demux to expect an input of size [4]?

You could either change the definition of rad to be 4-by-1 or the size specified to Simulink to be [1, 4].

Sign up to request clarification or add additional context in comments.

2 Comments

I see what you mean. I didn't know I had to manually set the output of the MATLAB function. Right-clicking the function block, selecting "Explore" and setting the output size to "[1 4]" did the trick. Thanks.
that works for me, but I'd prefer if the output size could be 'Inherited'. Do you have a suggestion for that? (Or is that a separate question?) Also... do you have any idea why taking a transpose doesn't solve the problem?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.