dimensions of matlab function block

조회 수: 7 (최근 30일)
Sarah Kern
Sarah Kern 2020년 1월 13일
답변: Walter Roberson 2020년 1월 14일
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?

채택된 답변

Walter Roberson
Walter Roberson 2020년 1월 14일
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.

추가 답변 (3개)

Chris Verhoeven
Chris Verhoeven 2020년 1월 13일
편집: Chris Verhoeven 2020년 1월 13일
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
Chris Verhoeven
Chris Verhoeven 2020년 1월 13일
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
Sarah Kern
Sarah Kern 2020년 1월 13일
I am sorry, I try to be clearer
I have an analytical optimization
function [Fx1, Fy1, Fx2, Fy2, Fx3, Fy3, Fx4, Fy4] = myfunction
ParameterSarah;
%Definition der Rad-Fahrzeug-Kopplung
G = [1,0,1,0,1,0,1,0;
0,1,0,1,0,1,0,1;
-w_l,l_v,w_r,l_v,-w_l,-l_h,w_r,-l_h];
%Definition des Rechtsannihilators G_ra
G_Ra = [1,0,0,0,-((l_v+l_h)/(w_l+w_r)); 0,0,1,0,0; 0,1,0,0,(l_v+l_h)/(w_l+w_r); 0,0,-1,0,-1; -1,0,0,0,0; 0,0,0,1,1; 0,-1,0,0,0; 0,0,0,-1,0];
%Definition der Moore-Penrose Inverse G_plus
G_Moore = transpose(G)*inv((G*transpose(G)));
%Definition der Gewichtungsmatrix Q
Q = [1/F_max/(1) 0 0 0 0 0 0 0;
0 1/F_max(1) 0 0 0 0 0 0;
0 0 1/F_max(2) 0 0 0 0 0;
0 0 0 1/F_max(2) 0 0 0 0;
0 0 0 0 1/F_max(3) 0 0 0;
0 0 0 0 0 1/F_max(3) 0 0;
0 0 0 0 0 0 1/F_max(4) 0;
0 0 0 0 0 0 0 1/F_max(4)];
%Bestimmung der fünf Kraftparameter für die minimale Kraftschlussausnutzung
%deltax = -inv((transpose(G_Ra)*Q*G_Ra))*transpose(G_Ra)*Q*G_Moore*v;
%Bestimmung des realen Stellvektors
%y=[Fx1, Fy1, Fx2, Fy2, Fx3, Fy3, Fx4, Fy4]^T
%y=G_Moore*F_soll+G_Ra*deltax;
F_soll = [Fx_V; Fy_V; Mz_v];
myfunction = (G_Moore-G_Ra*inv((transpose(G_Ra)*Q*G_Ra))*transpose(G_Ra)*Q*G_Moore)*F_soll;
Fx1 = myfunction(1);
Fy1 = myfunction(2);
Fx2 = myfunction(3);
Fy2 = myfunction(4);
Fx3 = myfunction(5);
Fy3 = myfunction(6);
Fx4 = myfunction(7);
Fy4 = myfunction(8);
end
and I want to use it in my matlab function block
function [Fx1, Fy1, Fx2, Fy2, Fx3, Fy3, Fx4, Fy4]= fcn(u)
%Parameter laden
coder.extrinsic('Mosebergfct')
Mosebergfct;
coder.extrinsic('ParameterSarah')
ParameterSarah;
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);
Fx1 = zeros;
Fy1 = zeros;
Fx2 = zeros;
Fy2 = zeros;
Fx3 = zeros;
Fy3 = zeros;
Fx4 = zeros;
Fy4 = zeros;
y = @myfunction;
end
I read that in a matlab function block I have to define the output dimensions first and haope I can do this with the Fx1 = zeros. So far I always get the error that there is to less information and the output dimensions can not be defined

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


Chris Verhoeven
Chris Verhoeven 2020년 1월 13일
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

Chris Verhoeven
Chris Verhoeven 2020년 1월 13일
  댓글 수: 1
Sarah Kern
Sarah Kern 2020년 1월 13일
Its in a matlab function block, so all I need the function to do to take the inputs which I defined as the vector u and calculate the Fxis. I am not allowed to define another function in the matlab function block, so I needed to create another skript with the second function. And without the definition Fx=zeros, Simulink couldnt handle the function outputs. What do you mean I am stuck in the loop?

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

카테고리

Help CenterFile Exchange에서 Sources에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by