simulink matlab function dimension error

조회 수: 4 (최근 30일)
태건
태건 2025년 9월 22일
댓글: Sam Chak 2025년 9월 23일
In my first Matlab function, I set the input to a 4x1 vector, a feedback vector, and a scalar, but the output is a scalar. Please tell me how to make the output a 4x1 vector. I have attached my simulink file
  댓글 수: 2
dpb
dpb 2025년 9월 22일
A short reproduction using your stated dimensions
sp_des=100*rand(4,1);
sp=90;
r=0.117;
drag=0.1;
k_t=60/2/pi/960*3450;
k_e=k_t;
v=k_e.*sp_des + r.*drag.*sp.^2./k_t
v = 4×1
1.0e+03 * 0.9439 3.1334 2.6774 1.4427
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
illustrates that the result would be the 4-vector if the input variables are the desired sizes.
Therefore, it must be presumed that the variable motor_speed_des isn't atually being passed as the 4-vector, but only a scalar value from it.
Set a breakpoint in the m-function and inspect the input variables.
I am unfamiliar with Simulink so I don't know precisely how it calls the function, but something must be amiss there...
Sam Chak
Sam Chak 2025년 9월 23일
Using Selector block proposed by @Angelo Yeo is technically sufficient.
Consider the Simulink block as analogous to a 4-speed table fan, where you can select only one speed at a time from a range of options. If you require a 4x1 output vector, you can use 4 "fans" or duplicate the motor block 3 additional times, followed by a vertical concatenation of the 4 individual outputs.

댓글을 달려면 로그인하십시오.

답변 (1개)

Angelo Yeo
Angelo Yeo 2025년 9월 22일
It's a variable type/dimension inheritance issue. The subsystem I marked with red rectangle expects 1-dimensional input (voltage), and Simulink tries to inherit the 1-dim dimensionality to VoltageConversion MATLAB Function's output. So, you should be changing the behavior of the subsystem in red rectangle.
For example, in the subsystem with red rectangle, you can choose which element of 4-dim vector, "voltage" to use with Selector block like below. In the case below, the second element is being used. And, see that the dimension issue is fixed for this particular input port "voltage".

카테고리

Help CenterFile Exchange에서 Interactive Model Editing에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by