How to correct error in port width or dimension in simulink ?

760 views (last 30 days)
I am getting the following port dimension errors when I try to run my simulink model:
"Invalid setting for input port dimensions of 'CONT_assignment/Demux1'. The dimensions are being set to [-1]. This is not valid because the total number of input and output elements are not the same"
"Error in port widths or dimensions. Invalid dimension has been specified for output port 1 of 'CONT_assignment/Transfer Fcn'."
Here is an image of the model. It's a simple PID controller model. The controller gain values are specified in a .m file as global parameters.
Does anyone have a solution for this ?

Accepted Answer

Walter Roberson
Walter Roberson on 16 Jun 2018
The blocks between Add1 through to Transfer Fcn: set any one of them to explicitly have an output width of 1.
The difficulty you are having is that with your loop the way you have it set up, it would be valid for you to be having a vector of any size being propagated. For example if the vector were of length 5 out of Add1, then that would go into the PID, which would create an output of length 5, which would go into Gain5, which would create an output of length 5, which would go into Gain4, which would create an output of length 5, which would go into Add2 which would produce an output of length 5, which would go into the Transfer Fcn, which would produce an output of length 5, which would go into the DeMux. But the Demux has not been told how to split up that input of length 5 because you have not told it how many values go to which output. If we suppose the bottom one were to get 5 outputs, then that would feed back in to Add1 and the loop would be complete and there would not be any problem with that part -- so a vector output is not inconsistent with any of those blocks. And that in turn means that Simulink cannot deduce what size it is supposed to be using. If you were to fix the output size from any one of the blocks, especially the Add1 block, then Simulink would be able to figure out all of the down-stream sizes.
However, look again at the Demux block. In order to demux, you have to be splitting the input up into multiple paths, so each of the outputs must be smaller than the inputs. So if you were sending a scalar through those Add1 and so on blocks, you would have a scalar out of the transfer fcn, going into the demux. Now you have at least two outputs from the demux but only one input, and that is a problem.
Demux is for splitting vectors. I don't think you want to be splitting the output of the transfer function: I think you want the same scalar output to be going to Add1 and the scope block. Which does not require any block: just connect both to the same input.
  3 Comments
Tong Zhao
Tong Zhao on 8 Jan 2022
Edited: Tong Zhao on 8 Jan 2022
Thank you for the answer, it solved my similar problem too. I was having errors while opening my older models created in MATLAB R2020b in a newer version R2021b. And the error I got was
The dimensions are being set to 1. This is not valid because the total number of input and output elements are not the same
And following your comment I resolved it by forcing one of the blocks on the chain of questionable/undetermined dimension to have an explicit signal dimension of 1.
Mohammad khosravani
Mohammad khosravani on 24 May 2023
Hi
I have the same problem with a small difference. I have develpoed a subsystem and every thing works well. but when I put it in a bigger simulation model, I receive this message. the inputs are the same but I do not know what is the problem?

Sign in to comment.

More Answers (1)

Achille Jacquemond
Achille Jacquemond on 16 Jun 2018
Thank you. I removed the Demux and it seems to work.
I just don't understand how to "set any one of them to explicitly have an output width of 1"
How to do this ?

Categories

Find more on Interactive Model Editing in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!