Inferred size ('[1 20]') for data 'MyMatrix_ToVector' does not match back propagated size ('[20]') from Simulink.

32 views (last 30 days)
Hello,
when using Simulink with a Matlab-Function I have the issue that the dimensions do not match, [1 20] vs [20]. How can I convert to a [20] array? I cannot modify the block that expects the [20] array because it is a compiled function.
Code:
lengthOf_MyMatrix = numel(MyMatrix); % evaluate the targets size, it's a 4*5 Matrix
MyMatrix_ToVector = reshape(MyMatrix,1,lengthOf_MyMatrix); % Try to shape it to a Vector
Error-Message: Inferred size ('[1 20]') for data 'MyMatrix_ToVector' does not match back propagated size ('[20]') from Simulink.
Thank you very much,
Best Regards, Sebastian Wendel
  1 Comment
Sebastian Wendel
Sebastian Wendel on 8 Sep 2020
P.S. I had some tries to fix it, now I get:
Error-Message: Failed to resolve data 'MyMatrix_ToVector' in 'MySimulinkFunction/MATLAB Function' to a valid Simulink.Signal object.

Sign in to comment.

Answers (2)

Sebastian Wendel
Sebastian Wendel on 11 Sep 2020
Edited: Sebastian Wendel on 11 Sep 2020
Dear Uday,
thank you very much, sorry for the late reply. The Matlab-Block is actually connected to a dSpace Flash Block which is a [20] Array.
I was able to fix it yesterday with the following code and setting:
Code:
lengthOf_MyMatrix = numel(MyMatrix); % evaluate the targets size, it's a 4*5 Matrix
MyMatrix_ToVector = reshape(MyMatrix,1,lengthOf_MyMatrix)'; % Try to shape it to a Vector
Ports and Data Manager:
Best Regards, Sebastian Wendel
P.S. Sorry that I had to change the variable-names, not to publish details officially. This is the Simulink-Section:

Uday Pradhan
Uday Pradhan on 11 Sep 2020
Hi Sebastian,
You can try editing the size of the output of your MATLAB function. To do this, follow these steps:
  1. Open the MATLAB function in the MATLAB editor.
  2. Now click on the "EDITOR" tab if you are already not on that tab.
  3. Search for "Edit data" option in the pane. It should be next to the "Build Model" option.
4.A new window called "Ports and Data Manager" should open up.
5. Select the output in the left pane and edit the Size to [1 20] instead of -1
Apply the settings and run the model again. I hope this resolves the issue.
  1 Comment
laiche zeghdi
laiche zeghdi on 19 Sep 2023
i have almost same problem how can fixed this (Inferred size ('scalar') for data (#28) does not match back propagated size ('Sa') from Simulink

Sign in to comment.

Categories

Find more on Event Functions in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

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

Start Hunting!