# Implementing Matlab code in a Simulink Matlab function

조회 수: 2(최근 30일)
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 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.

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

### 범주

Find more on Sources in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!
{"ft_lang_label":"__label__en","ft_lang_prob":0.6201957,"math_prob":0.944861,"size":1940,"snap":"2022-40-2023-06","text_gpt3_token_len":567,"char_repetition_ratio":0.20609504,"word_repetition_ratio":0.008163265,"special_character_ratio":0.28659794,"punctuation_ratio":0.11764706,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9945933,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-02-01T10:38:06Z\",\"WARC-Record-ID\":\"<urn:uuid:aac5bceb-4062-40d3-8543-5f2101e37c65>\",\"Content-Length\":\"124049\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:ad05ef28-49cc-4d52-bf4b-1c9284dce4b8>\",\"WARC-Concurrent-To\":\"<urn:uuid:d55ca15e-5496-49f9-9788-a08a3320f5b5>\",\"WARC-IP-Address\":\"104.86.80.92\",\"WARC-Target-URI\":\"https://kr.mathworks.com/matlabcentral/answers/1689945-implementing-matlab-code-in-a-simulink-matlab-function?s_tid=prof_contriblnk\",\"WARC-Payload-Digest\":\"sha1:BV5BJ7RZ7VTPTMPBU7S5VU3M7PVJ5GGU\",\"WARC-Block-Digest\":\"sha1:642FZZLQRVD6AEPFWTJ7RZVXGSGCY3R2\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-06/CC-MAIN-2023-06_segments_1674764499919.70_warc_CC-MAIN-20230201081311-20230201111311-00489.warc.gz\"}"}