Borrar filtros
Borrar filtros

Matlab Function outputs strange dimensions, despite these being explicitally defined

2 visualizaciones (últimos 30 días)
Hello all,
I have created a fairly complex model in Simulink.
For the sake of good understanding, I'm posting an image of a simplified version. I trust the simplifications here used do not hide any detail that could potentially lead to an answer, but feel free to ask for more details.
The system is as it follows:
There are two main sections: Machines & Network.
The logic behind works like this:
Each one of the machines calculates a desired mechanical effort. From that mechanical effort it estimates the power needed. To this power is added a power of a somehow independent subsystem inside each one of the machines.
Each one of the machines has two outputs, the power demanded and its position in the network, so to speak.
These outputs are the inputs of the network. The network is composed by a Matlab Function Block that outputs the current and voltage for each one of the machines (in the form of a matrix with the size 4x3).
Resorting to selectors, we split the output of the Matlab Function to each one of the machines, and feed this as an input.
The machines take this information and calculate how much mechanical effort are they able to do.
Everything works fine while I use the calculated position in the calculation of the Power Demanded. But when I try that the Position to be used everywhere to be the one outputted from the Power Available to Mechanical Effort, it gives me an error of dimensions, which frankly, I was not expecting. And even more strange is the location of the error, it gives me this error in the output of the Matlab Function in the Network, as if it was a [1x1] matrix, despite being initialized in the beginning of the Function with a
Machines=zeros(4,3);.
The global vision of the system:
Inside one of the machines:
Inside the network:
As you can see, I tried using a IC in order to correctly initialize the value of the position, as this seems to me as some sort of algebraic loop, but in vain, as it does not solve the problem.
The two errors it gives me:
Invalid dimensions being set to input port <U> of 'dummy/Network/Voltage'. The port is being set to have the dimensions [1x1], while an aggregation of parameters and port dimensions indicate that the dimensions should be consistent with [?x3]
Component:Simulink | Category:Modelerror
Error in port widths or dimensions. Output port 1 of 'dummy/Network/MATLAB Function2' is a [1x1] matrix.
Any help would be highly appreciated.
Thank you for your time reading this.
EDIT OP+1: Contrary to what I said, I did not set the size of the output of the matlab function directly as
Machines=zeros(4,3);
But rather as
nt=length(x); Machines=zeros(4,nt);
In order to allow for the inclusion of a variable number of machines. Today I understood that actually hard coding the size fixes the error, while using a constant as an input to the function makes Simulink think it is a variable size matrix (when it is not). I do need however the number of machines considered to be variable. And I do not understand how can it output a [1x1] matrix.
I also saw that putting an IC right after the matlab function with the values (zeros(4,3)) makes the error transform itself in "the output of the Matlab function is a [4x1] size".
I honestly have no idea of why is Simulink thinking this.

Respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by