dimensions of matlab function block
5 views (last 30 days)
Show older comments
Sarah Kern
on 13 Jan 2020
Answered: Walter Roberson
on 14 Jan 2020
Hello,
I have the following code
function [Fx1, Fy1, Fx2, Fy2, Fx3, Fy3, Fx4, Fy4]= fcn(u)
%Parameter laden
Moseberg;
F_max = (1:4);
%Input definition
% target trajectory
Fx_V = u(1);
Fy_V = u(2);
Mz_V = u(3);
%calculated friction border
F_max(1) = u(4);
F_max(2) = u(5);
F_max(3) = u(6);
F_max(4) = u(7);
y = @m;
but I keep getting these errors.
This text contains non-empty top-level expressions. It appears to be a script.
Function 'Moseberg.m' (#51.0.0), line 0, column 0:
""
Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Errors occurred during parsing of MATLAB function 'FTR_diskret/CarMaker/VehicleControl/FTR1/Fahren/Aufteilung der Überaktuierung /Kräfteaufteilung/kritischer Fahrbereich/MATLAB Function'
Component:MATLAB Function | Category:Coder error
Simulink cannot determine sizes and/or types of the outputs for block 'FTR_diskret/CarMaker/VehicleControl/FTR1/Fahren/Aufteilung der Überaktuierung /Kräfteaufteilung/kritischer Fahrbereich/MATLAB Function' 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
Compilation of model 'FTR_diskret' failed while trying to resolve underspecified signal dimensions.
Suggested Actions
Enable 'warning' or 'error' diagnostics for the list of underspecified signal dimensions.
Open
Caused by:
Simulink cannot determine sizes and/or types of the outputs for block 'FTR_diskret/CarMaker/VehicleControl/FTR1/Fahren/Aufteilung der Überaktuierung /Kräfteaufteilung/kritischer Fahrbereich/MATLAB Function' 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.
Error occurred in 'FTR_diskret/CarMaker/VehicleControl/FTR1/Fahren/Aufteilung der Überaktuierung /Kräfteaufteilung/kritischer Fahrbereich/MATLAB Function'.
Can someone help me how to fix the dimensions?
0 Comments
Accepted Answer
Walter Roberson
on 14 Jan 2020
It looks to me as if MATLAB Function Block cannot invoke scripts .
Your Moseberg appears to be a script.
coder.extrinsic('Mosebergfct')
Mosebergfct;
coder.extrinsic('ParameterSarah')
ParameterSarah;
You are using Mosebergfct and ParameterSarah as if they are scripts as well. You should convert them into functions (returning appropriate variables) that are called each time, or else convert them into functions that you call once at the beginning and pass the values around.
Simulink Code Generator demands a lot of transparency.
0 Comments
More Answers (3)
Chris Verhoeven
on 13 Jan 2020
Edited: Chris Verhoeven
on 13 Jan 2020
You should end the function with end. And then you can call upon the function in a matlab file which is located in the same folder or in the same script.
function [Fx1, Fy1, Fx2, Fy2, Fx3, Fy3, Fx4, Fy4]= fcn(u)
%% code
end
3 Comments
Chris Verhoeven
on 13 Jan 2020
To be honest, i'm not sure what your problem is exactly. Could you try to explain it better? And have you used functions before, because to me it seems like you might not understand the purpose of a function. The function requires an input and an output and it does not know anything else except the input and the code it contains.
This is useful if you want to use a piece of code multiple times. For example if you want to calculate the side C of a triangle where C represents the length of the hypotenuse and A and B the lengths of the triangle's other two sides.
clear all, clc
side1 = 1;
side2 = 2;
side3 = pythagoras(side1,side2)
%% Function this can be in a seporate matlab function file
% or at the bottom of your script
function [C] = pythagoras(A,B)
C = sqrt(A.^2+B.^2) %pythagoras theorem
end
Of course this is a really simple function but I hope you get the idea. If this is not sufficient, please make your problem clear so I can help you better :)
~Chris
Chris Verhoeven
on 13 Jan 2020
You dont have to define your output as Fx1 = zeros. As long ase somewhere in the output variables are calculated somewhere in the function its fine.
But i'm confused. You have two functions in this file, but no code that uses the functions. Also the first function "myfunction" has no input requirements (so why use a function) and calls itself later in the same function "Fx1 = myfunction(1);" and here you use a input variable of 1 but you didn't define that the function needed an input in the first place. Calling upon a function in it's own function is not possible since it'll create an infinite loop.
Functions are there to make things easier, but they are not always necessary to use.
~Chris
0 Comments
See Also
Categories
Find more on General Applications in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!