Simulink Matrix multiply error: unexpected scalar signal mismatch

17 visualizzazioni (ultimi 30 giorni)
I'm confused by a Simulink error relating to a "mismatched port size".
I have a scalar signal in a feedback loop -- the exact configuration isn't relevant (I think), but the point is that it's a number (not vector) as far as I can tell: I know this is a single number, because I can Display it as a single number, and/or Show Value of the wire during running.
If I insert a simple filter inline with this number output from the matrix multiply, I get an error of matrix multiply propagation error.
Here's what works:
I display dims on all signals, so no display means scalar.
This doesn't work:
SL is confused on dims for some reason.
Error:
Why? Isn't a matrix multiply output just a number, if the dimensions end up as 1x1?
What am I misunderstanding?
I haven't found any block options to force proper dims.
  2 Commenti
Walter Roberson
Walter Roberson il 29 Apr 2023
Why would the dimension end up as 1 x 1? Your second calculation appears to do matrix multiplication of two 1 x 2, which would be an error.
Or possibly your [Kx] is intended to be 2 x 1 -- but Simulink notes 2 x 1 differently than 2 .
If [Kx] is intended to be 2 x 1 your might need to put it through a reshape block.
John
John il 30 Apr 2023
Modificato: John il 30 Apr 2023
@Walter Roberson "Why would the dimension end up as 1 x 1"
1x2 * 2x1 = 1x1
I thought the output dims is verified as 1 for the reasons in the original post... is my thinking wrong?
It also goes into a summing junction that is only scalar 1x1 values, so anything not 1x1 wouldn't work in the first place, even in the case without a filter, that I show does work:
"Simulink notes 2 x 1 differently than 2"
Ah -- interesting; I didn't know that. Kx is a 2-element vector obtained from a 4-element input, broken up like so:
Kd =
4.4954e+02 1.6826e-01 1.0000e+00 -1.6037e+05
Just to check, are you saying that Kx is not 2x1 as I thought it was?
"you might need to put it through a reshape block."
I see...i already thought it was 2x1, so how would I do that?

Accedi per commentare.

Risposta accettata

Paul
Paul il 29 Apr 2023
That block mutiplies the inputs from top to bottom as if they are left to right. So that block is really doing
xh * Kx,
when you want it the other way around. So make Kx go into the top port and xh into the bottom port.
Then, you need to make sure that Kx is truly a 1x2 vector (or xh is a 2x1). Does Kx source from a Constant block? If it does, make sure that in that block the "Constant value" parameter is a row vector and uncheck the 'Interpret vector paramters as 1D'.
  6 Commenti
Paul
Paul il 3 Mag 2023
But why is it neccessary to have the gains as input signals to a subsystem in the first place? If that helps provide you visual clarity of the diagram, or if there is some other reason to structure the model that way, then doing it that way is fine.
All I was saying is that you don't have to do it that way. Instead you can just use Gain blocks where you need them inside the relevant subsystems and set the Gain parameters of those blocks to be the necessary elements of Kd. Doing it this way, the block diagram looks more like the control system you're modeling, IMO. I was just pointing this out in case you weren't aware that a Simulink block parameter can be any Matlab expression, like Kd(1:2); it doesn't have to be a Matlab variable name.
John
John il 3 Mag 2023
"All I was saying is that you don't have to do it that way. Instead you can just use Gain blocks where you need them inside the relevant subsystems and set the Gain parameters of those blocks to be the necessary elements of Kd. "
Yes, thanks :) I was aware of that, but appreciate you mentioning just in case.
"But why is it neccessary to have the gains as input signals to a subsystem in the first place? If that helps provide you visual clarity of the diagram, or if there is some other reason to structure the model that way, then doing it that way is fine."
It's so that i can have a common reference subsystem that i can use in multiples places, but have inputs that vary for each equivalent instantiation.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by