Error in Sliding Mode Controller Code

6 Ansichten (letzte 30 Tage)
Junaid
Junaid am 8 Mär. 2025
Kommentiert: Junaid am 8 Mär. 2025
I am facing error in my matlab simulink mode for sliding mode controller using reaching law and boundary layer function to reduce chattering.
I am not sure what I am doing wrong. I crossed checked my equations and implementations but they all look right to me. My simulink file is attached in the post. it has all functions necessary to run the model independently.
The error is:
Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication.
Function 'MATLAB Function' (#32.427.430), line 21, column 30:
"C*f"
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Block ''clutch_SlidingModeControl/MATLAB Function'' does not fully set the dimensions of output 'output'.

Akzeptierte Antwort

Jack
Jack am 8 Mär. 2025

The error arises because the dimensions of C and f are not compatible for matrix multiplication. In MATLAB, when you use the * operator, the number of columns in C must equal the number of rows in f. If you intended to multiply the elements individually, you should use elementwise multiplication (.*) instead.

Double-check the sizes of your matrices inside the MATLAB Function block—ensure that C and f are defined with matching dimensions if you really want to use matrix multiplication. Also, note that the warning about the output not being fully set means you should explicitly assign the dimensions of your output variable, possibly by preallocating it or ensuring every code path sets it.

Follow me so you can message me anytime with future questions. If this helps, please accept the answer and upvote it as well.

  4 Kommentare
Sam Chak
Sam Chak am 8 Mär. 2025
Hi @Jack, from a control expert's perspective, if there is no dimensional error, have you thoroughly verified whether the sliding mode control law has been correctly implemented?
function output = Sliding_Mode(e, edot, eta, K, C, phi, A, B, x, u)
% Sliding Surface
s = C*e;
% Boundary Layer Function to reduce chattering
if (abs(s) > phi)
theta = 1;
elseif (abs(s) <= phi)
theta = 1/phi;
else
theta = -1;
end
% Exponential Reaching Law
h = - eta*theta - K*s;
g = B*u;
f = A*x;
% Control Output
output = (C*g)\(C*edot - C*f + h);
end
Junaid
Junaid am 8 Mär. 2025
Hello @Sam Chak and @Jack,
I solved this problem by using MATLAB R2024b version which has in-build Sliding Mode Controller with Reaching Law in Simulink.
Using that I figured my matrix mismatch issue as well and it works now. Thank you for your help.
Thanks
Junaid

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Test Execution finden Sie in Help Center und File Exchange

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by