Creating Function in Files in MATLAB Last Updated : 28 Apr, 2025 Comments Improve Suggest changes 2 Likes Like Report MATLAB is a high-performance language that is used for matrix manipulation, performing technical computations, graph plottings, etc. It stands for Matrix Laboratory. Functions:The function is a set of statements or commands, which take input/s as parameters and return output. We write functions to use it again and again in the program i.e. it makes a block of code reusable. It makes it easier to find errors and also reduces code redundancy. Types of Function:Library Functions: In MATLAB Software, there are some inbuilt functions, which take input as arguments and return output. E.g. log(x), sqrt(x), line space(a,b,n), etc.User-Defined Functions: In MATLAB, we also create functions by writing Matlab commands in files that take input/s as argument/s and then return the output. Also, save the function file using the name of the function itself. Steps to Create a Function File in MATLAB:Step 1: Create a file and write commands using the function keyword.Step 2: Save the function file with the same name as the function. Here I have saved the file with the name solve.m.Step 3: Use the function in Command Video by providing suitable argument/s.Now we see creating a function and saving it in MATLAB. Example 1: Matlab % function to calculate sin(x)+cos(x) where x is in radians % Here solve is the name of the function which % will return x and takes an argument a function x = solve(a) x = sin(a) + cos(a); Using the function to be called in Command Window. Example 2: Matlab input = 1.5708; % display the function's output disp(solve(input)); Output: The above screenshot is showing: Function saved as a file named solve.mCommand Window in which we are calling function for various inputs. Comment A akashish__ Follow 2 Improve A akashish__ Follow 2 Improve Article Tags : Software Engineering MATLAB-Functions Explore Software Engineering BasicsIntroduction to Software Engineering7 min readSoftware Development Life Cycle (SDLC)8 min readSoftware Quality - Software Engineering5 min readISO/IEC 9126 in Software Engineering4 min readBoehm's Software Quality Model4 min readSoftware Crisis - Software Engineering3 min readSoftware Measurement & MetricesSoftware Measurement and Metrics4 min readPeople Metrics and Process Metrics in Software Engineering7 min readHalsteadâs Software Metrics - Software Engineering10 min readCyclomatic Complexity6 min readFunctional Point (FP) Analysis - Software Engineering8 min readLines of Code (LOC) in Software Engineering4 min readSoftware Development Models & Agile MethodsWaterfall Model - Software Engineering12 min readWhat is Spiral Model in Software Engineering?9 min readPrototyping Model - Software Engineering7 min readIncremental Process Model - Software Engineering6 min readRapid Application Development Model (RAD) - Software Engineering9 min readCoupling and Cohesion - Software Engineering10 min readAgile Software Development - Software Engineering15+ min readSRS & SPMSoftware Requirement Specification (SRS) Format5 min readSoftware Engineering | Quality Characteristics of a good SRS7 min readSoftware Project Management (SPM) - Software Engineering8 min readCOCOMO Model - Software Engineering15+ min readCapability Maturity Model (CMM) - Software Engineering10 min readIntegrating Risk Management in SDLC | Set 18 min readSoftware Maintenance - Software Engineering13 min readTesting & DebuggingWhat is Software Testing?11 min readTypes of Software Testing15+ min readTesting Guidelines - Software Engineering3 min readWhat is Debugging in Software Engineering?11 min readVerification & ValidationVerification and Validation in Software Engineering6 min readRole of Verification and Validation (V&V) in SDLC5 min readRequirements Validation Techniques - Software Engineering8 min readPractice QuestionsTop 50+ Software Engineering Interview Questions and Answers15+ min read Like