How to turn a script into a function so later i can make the code executable with Matlab Coder

I want to use Matlab Coder to turn my code into a .exe file so people who don't have matlab can use it but Matlab Coder doesn't accept script and i can't figure out how to change it into a function
My code basically asks for midterm1 and midterm2 grades of the student and prints out average grade of the student to a txt file after combining midterm grades with hypothetical final and oral exam grades
clear all;
close all;
clc;
MT1 = input('ilk midtermden kaç aldın MT1:');
MT2 = input('ikinci midtermden kaç aldın MT2:');
OE = 0.1:0.1:0.4;
F = 60:1:100;
R=(MT1+MT2)*0.3+F*0.4;
for i=1:4
T(:,i+1)=R*(0.6+OE(i));
end
for j=1:41
T(j,1)=j+59;
end
b=[0 0.1 0.2 0.3 0.4];
K=[b;T];
writematrix(K,'blabla.txt','Delimiter','tab')
type 'blabla.txt'

2 件のコメント

Rik
Rik 2021 年 1 月 17 日
Any basic Matlab tutorial will teach you how to make functions. In your case it might be as simple as adding the word function followed by the name of your file (without .m)
And why are you ignoring the mlint warning? You don't need clear all. Especially when using a function.
Cavit Ertugrul Sirt
Cavit Ertugrul Sirt 2021 年 1 月 17 日
編集済み: Cavit Ertugrul Sirt 2021 年 1 月 17 日
thank you, i didn't realise it was that easy

サインインしてコメントする。

 採用された回答

Cris LaPierre
Cris LaPierre 2021 年 1 月 18 日
編集済み: Cris LaPierre 2021 年 1 月 18 日
+1 to what Rik said.
However, this is a good opportunity to point out that the MATLAB live editor now has the capability of converting selected code into a live function. This is called refactoring. You can see instructions on how to use this feature in the Create Live Function from Selected Code section here.

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by