7 views (last 30 days)

Show older comments

Hi, I'm pretty new to Matlab, I'm programming an M function in simulink and getting the following errors. Any help would be appreciated. The input setPoint is from a constant block (double, 400000) and the input grid Voltage is from a continuous RMS monitor block reading a converter driven AC bus voltage. The bus is supposed to start dead, then energise. The output plantOutput will control a PWM controller. Using Matlab r2018a.

Simulink does not have enough information to determine output sizes for this block. If you think the errors below are inaccurate, try specifying types for the block inputs and/or sizes for the block outputs.

Component:MATLAB Function | Category:Coder error

Dimension 1 is fixed on the left-hand side but varies on the right ([1 x 1] ~= [:? x 1]).

Function 'Subsystem3/PWM mod controller/MATLAB Function1' (#49.1298.1300), line 56, column 5:

"ed"

Launch diagnostic report.

Component:MATLAB Function | Category:Coder error

Dimension 1 is fixed on the left-hand side but varies on the right ([1 x 1] ~= [:? x 1]).

Function 'Subsystem3/PWM mod controller/MATLAB Function1' (#49.1328.1330), line 58, column 5:

"cd"

Launch diagnostic report.

Component:MATLAB Function | Category:Coder error

Function call failed.

Function 'Subsystem3/PWM mod controller/MATLAB Function1' (#49.377.387), line 19, column 13:

"pid(error)"

Launch diagnostic report.

Component:MATLAB Function | Category:Coder error

Errors occurred during parsing of MATLAB function 'Custom_Interconnector_stage_9_DC_TEST/Subsystem3/PWM mod controller/MATLAB Function1'

Component:MATLAB Function | Category:Coder error

Simulink cannot determine sizes and/or types of the outputs for block 'Custom_Interconnector_stage_9_DC_TEST/Subsystem3/PWM mod controller/MATLAB Function1' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.

Component:MATLAB Function | Category:Coder error

Simulink cannot determine sizes and/or types of the outputs for block 'Custom_Interconnector_stage_9_DC_TEST/Subsystem3/PWM mod controller/MATLAB Function1' due to errors in the block body, or limitations of the underlying analysis. The errors might be inaccurate. Fix the indicated errors, or explicitly specify sizes and/or types for all block outputs.

Component:Simulink | Category:Model error

Error occurred in 'Custom_Interconnector_stage_9_DC_TEST/Subsystem3/PWM mod controller/MATLAB Function1'.

Component:Simulink | Category:Model error

function plantOutput = modIndex(gridVoltage, setPoint)

persistent controlOutput;

persistent error;

persistent PIDOutput;

if (isempty(controlOutput))

controlOutput = 0.0;

end

if (isempty(error))

error = 0.0;

end

if (isempty(PIDOutput))

PIDOutput = 0.0;

end

error = setPoint - gridVoltage; %negative feedback %gridVoltage here

PIDOutput = pid(error);

plantOutput = plant(PIDOutput);

end

%compute the controller output

%in: current error

%return: PID output

function PIDOutput = pid(error)

kp = 4.0;

kd = 2.0;

ki = 0.5;

tf = 4.0;

h = 0.1;

persistent ed;

persistent edd;

persistent cd;

persistent cdd;

if (isempty(ed))

ed = 0.0; %error(k-1)

end

if (isempty(edd))

edd = 0.0; %error(k-2)

end

if (isempty(cd))

cd = 0.0; %PIDOutput(k-1)

end

if (isempty(cdd))

cdd = 0.0; %PIDOutput(k-2)

end

%differential equation for current PIDOutput, derived from the given TF

PIDOutput = (error * (4 * kd + 4 * kp * tf + 2 * kp * h + 2 * ki * tf * h + ki * h * h) + ed * (-8 * kd - 8 * kp * tf + 2 * ki * h * h) + edd * (4 * kd + 4 * kp * tf - 2 * kp * h - 2 * ki * tf * h + ki * h * h) - cdd * (4 * tf - 2 * h) + cd * (8 * tf)) / (4 * tf + 2 * h);

edd = ed;

ed = error;

cdd = cd;

cd = PIDOutput;

end

%compute the plant output

%in: PID output

%return: plant output plantOutput

function plantOutput = plant (PIDOutput)

k = 2.0;

t = 3.0;

h = 0.1;

persistent cd;

persistent yd;

if (isempty(cd))

cd = 0.0; %PIDOutput(k-1)

end

if (isempty(yd))

yd = 0.0; %plantOutput(k-1)

end

%differential equation for current plantOutput, derived from the given TF

plantOutput = exp(-(1 / t) * h) * yd + (k - k * exp(-(1 / t) * h)) * cd;

cd = PIDOutput;

yd = plantOutput;

end

Mark McBroom
on 30 May 2020

The error means that one of your input signals to the ML Fcn block is variable length.

I pasted your code into a ML Fcn block, then created Simulink constant blocks for the two inputs and connected them to the two input ports on the ML Fcn block. The first constant I set to 400000, the second to 100... and the model ran fine. So, your constant block and/or RMS block must be outputing a variable length signal. I suggest replacing the RMS signal input with a constant block that outputs a scalar value to help narrow down the problem.

Thanks.

Mark.

Walter Roberson
on 30 May 2020

function plantOutput = modIndex(gridVoltage, setPoint)

After that line add assert() statements that test that each of the two inputs are scalar. Simulink will recognize the assert() as forcing input sizes to be 1x1 and then it will be to compile.

If it is not correct that the inputs are scalar then in the places you assign 0 to the persistent variables, you must instead assign a zeros() of appropriate size. Simulink cannot do dynamic expansion of a variable along the line of

x = scalar

x = x + vector

That works fine in MATLAB but not in Simulink

x = zeros(size(vector)) ;

x(:) = scalar;

x = x + vector

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

Start Hunting!