Implementing Matlab code in a Simulink Matlab function

조회 수: 2 (최근 30일)
MARCO LORENZI
MARCO LORENZI 2022년 4월 6일
답변: Ganesh Gudipati 2022년 4월 13일
Good morning everyone.
Could someone help me implement this code in Simulink?
Functions like makima or smooth does not seem to work in matlab function blocksets.
%% DATA INPUT
dynamic_pressure = 1027.924;
alpha_breakpoints_Fx = [-180 -165 -90 -15 -10 -5 0 5 15 30 60 90 120 150 165 180];
Fx_values = [-450 -395 -11 299 310 290 296 280 315 280 -18 -62 60 -640 -510 -450];
Fx_coefficients = Fx_values/dynamic_pressure;
%% SPACE ALLOCATION
Fx_coefficients_interpolation = zeros(1,360);
alpha_interpolation = zeros(1,360);
%% CUBIC SPLINE INTERPOLATION
for i = 1:361
alpha_interpolation(i) = i-181;
Fx_coefficients_interpolation(i) = makima(alpha_breakpoints_Fx,Fx_coefficients,alpha_interpolation(i));
end
%% Fx
der_Fx_sx = (Fx_coefficients_interpolation(2)-Fx_coefficients_interpolation(1))/(alpha_interpolation(2)-alpha_interpolation(1));
der_Fx_dx = (Fx_coefficients_interpolation(end)-Fx_coefficients_interpolation(end-1))/(alpha_interpolation(end)-alpha_interpolation(end-1));
der_Fx = mean([der_Fx_sx der_Fx_dx]);
Fx_coefficients_interpolation = smooth(alpha_interpolation,Fx_coefficients_interpolation,'sgolay',4);
I am basically trying to fit a set of data using a handmade lookup table using makima as the interpolation method and then smooth the trend of the result to avoid discontinuities.

답변 (1개)

Ganesh Gudipati
Ganesh Gudipati 2022년 4월 13일
Hi,
Once we define the matlab function block, the simulink generates code for that function block. In this case the functions makima and smooth donot support code generation.
Hope this helps.

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by